cd "/Users/vetsean/Downloads/TMYK Replication"

clear all
set more off
set matsize 4000 


************************************************
******* GENERATING DATASET FOR 1ST STUDY *******
************************************************


***** PART 1: CODING RESPONSES *****
************************************

set more off
set matsize 4000 


insheet using "Caitlin_Codings.csv", comma
rename * c= 
rename cid id
save CCodes, replace

clear all
insheet using "Julia_Codings.csv", comma
rename * j= 
rename jid id
save JCodes, replace

clear all
use CCodes, clear
merge 1:1 id using JCodes, nogenerate // No issues with merge - all rows merged
save CJCodes, replace

use CJCodes, clear

destring, replace force

	replace jo1_type = 4 if id == 410
	replace co1_type = 1 if id == 483
    replace jo1_type = 5 if id == 544
    replace jo1_type = 5 if id == 570
	replace jo1_type = 5 if id == 602
    replace co2_type = 3 if id == 9
	replace co2_type = 3 if id == 100
	replace co2_type = 3 if id == 173
	replace co2_type = 3 if id == 180
	replace jo2_type = 3 if id == 227
	replace co2_type = 3 if id == 297
	replace jo2_type = 3 if id == 322
	replace jo2_type = 2 if id == 411
	replace jo2_type = 4 if id == 412
	replace jo2_type = 3 if id == 507
	replace jo2_type = 6 if id == 522
	
replace jo1_info3 = 450 in 218

*Info codings
gen byte check11 = 1 if co1_info1==jo1_info1 // 117 disagreeements 
gen byte check12 = 1 if co1_info2==jo1_info2 // 128 d.
gen byte check13 = 1 if co1_info3==jo1_info3 // 127 d.
gen byte check21 = 1 if co2_info1==jo2_info1 // 148 d.
gen byte check22 = 1 if co2_info2==jo2_info2 // 145 d.
gen byte check23 = 1 if co2_info3==jo2_info3 // 157 d.
mvencode check11 check12 check13 check21 check22 check23, mv(0)
	// Pretty high levels of disagreeement on exact numeric code - ~25% are different

replace co1_know = 1 in 282 // Changed 2 to 1
replace co1_know = 1 in 486 // Changed 2 to 1


*** Resolving disputes between coders ***


* Start with those with only final number disagreeement (i.e., agreee on category and first subcategory)

gen byte agreee21 = substr(string(co1_info1), 1, 2)==substr(string(jo1_info1), 1, 2) & check11==0
gen byte agreee22 = substr(string(co1_info2), 1, 2)==substr(string(jo1_info2), 1, 2) & check12==0
gen byte agreee23 = substr(string(co1_info3), 1, 2)==substr(string(jo1_info3), 1, 2) & check13==0
gen byte agreee24 = substr(string(co2_info1), 1, 2)==substr(string(jo2_info1), 1, 2) & check21==0
gen byte agreee25 = substr(string(co2_info2), 1, 2)==substr(string(jo2_info2), 1, 2) & check22==0
gen byte agreee26 = substr(string(co2_info3), 1, 2)==substr(string(jo2_info3), 1, 2) & check23==0

* Those that agreee on the first number: 

gen byte agreee11 = substr(string(co1_info1), 1, 1)==substr(string(jo1_info1), 1, 1) & check11==0 & agreee21==0
gen byte agreee12 = substr(string(co1_info2), 1, 1)==substr(string(jo1_info2), 1, 1) & check12==0 & agreee22==0
gen byte agreee13 = substr(string(co1_info3), 1, 1)==substr(string(jo1_info3), 1, 1) & check13==0 & agreee23==0
gen byte agreee14 = substr(string(co2_info1), 1, 1)==substr(string(jo2_info1), 1, 1) & check21==0 & agreee24==0
gen byte agreee15 = substr(string(co2_info2), 1, 1)==substr(string(jo2_info2), 1, 1) & check22==0 & agreee25==0
gen byte agreee16 = substr(string(co2_info3), 1, 1)==substr(string(jo2_info3), 1, 1) & check23==0 & agreee26==0

* Those that agreee on none: 

gen byte noagreee1 = check11==0 & agreee21==0 & agreee11==0
gen byte noagreee2 = check12==0 & agreee22==0 & agreee12==0
gen byte noagreee3 = check13==0 & agreee23==0 & agreee13==0
gen byte noagreee4 = check21==0 & agreee24==0 & agreee14==0
gen byte noagreee5 = check22==0 & agreee25==0 & agreee15==0
gen byte noagreee6 = check23==0 & agreee26==0 & agreee16==0

gen rowagreee3 = check11 + check12 + check13 + check21 + check22 + check23
gen rowagreee2 = agreee21 + agreee22 + agreee23 + agreee24 + agreee25 + agreee26
gen rowagreee1 = agreee11 + agreee12 + agreee13 + agreee14 + agreee15 + agreee16
gen rowagreee0 = noagreee1 + noagreee2 + noagreee3 + noagreee4 + noagreee5 + noagreee6


* Column 1
gen int newcode1=.
replace newcode1=410 if id==8
replace newcode1=223 if id==10
replace newcode1=340 if id==17
replace newcode1=430 if id==18
replace newcode1=410 if id==20
replace newcode1=110 if id==22
replace newcode1=238 if id==25
replace newcode1=410 if id==43
replace newcode1=340 if id==44
replace newcode1=240 if id==45
replace newcode1=410 if id==79
replace newcode1=238 if id==82
replace newcode1=410 if id==100
replace newcode1=440 if id==108
replace newcode1=240 if id==116
replace newcode1=410 if id==123
replace newcode1=240 if id==134
replace newcode1=340 if id==137
replace newcode1=240 if id==159
replace newcode1=340 if id==174
replace newcode1=240 if id==177
replace newcode1=410 if id==182
replace newcode1=410 if id==193
replace newcode1=720 if id==194
replace newcode1=730 if id==212
replace newcode1=240 if id==227
replace newcode1=110 if id==228
replace newcode1=450 if id==233
replace newcode1=490 if id==238
replace newcode1=220 if id==240
replace newcode1=224 if id==245
replace newcode1=430 if id==248
replace newcode1=720 if id==271 // Come back and code beliefs-type questions in 720
replace newcode1=410 if id==275
replace newcode1=450 if id==277
replace newcode1=730 if id==282
replace newcode1=239 if id==311
replace newcode1=215 if id==319
replace newcode1=450 if id==339
replace newcode1=240 if id==345
replace newcode1=410 if id==365
replace newcode1=340 if id==372
replace newcode1=490 if id==378
replace newcode1=240 if id==411
replace newcode1=410 if id==415
replace newcode1=720 if id==421
replace newcode1=410 if id==429
replace newcode1=410 if id==433
replace newcode1=315 if id==438
replace newcode1=120 if id==439
replace newcode1=240 if id==449
replace newcode1=440 if id==453
replace newcode1=410 if id==486
replace newcode1=410 if id==505
replace newcode1=410 if id==513
replace newcode1=720 if id==514
replace newcode1=540 if id==524
replace newcode1=410 if id==527
replace newcode1=340 if id==539
replace newcode1=340 if id==547
replace newcode1=590 if id==555
replace newcode1=224 if id==563
replace newcode1=410 if id==564
replace newcode1=710 if id==565
replace newcode1=710 if id==589
replace newcode1=240 if id==594
replace newcode1=410 if id==601
replace newcode1=410 if id==602
replace newcode1=410 if id==603
replace newcode1=130 if id==604
* Agree on 2:
replace newcode1=220 if id==9
replace newcode1=219 if id==62
replace newcode1=219 if id==81 // Drugs
replace newcode1=220 if id==95
replace newcode1=219 if id==258
replace newcode1=110 if id==272
replace newcode1=219 if id==386
replace newcode1=219 if id==443
replace newcode1=219 if id==458
replace newcode1=219 if id==462
replace newcode1=220 if id==526
replace newcode1=220 if id==553
replace newcode1=219 if id==572
* Agree on 1:
replace newcode1=420 if id==2
replace newcode1=410 if id==6
replace newcode1=410 if id==21
replace newcode1=450 if id==26
replace newcode1=440 if id==55
replace newcode1=240 if id==85
replace newcode1=222 if id==96
replace newcode1=440 if id==98
replace newcode1=720 if id==109
replace newcode1=218 if id==135
replace newcode1=730 if id==140
replace newcode1=234 if id==163
replace newcode1=239 if id==172
replace newcode1=440 if id==236
replace newcode1=410 if id==244
replace newcode1=440 if id==289
replace newcode1=239 if id==298
replace newcode1=440 if id==308
replace newcode1=220 if id==316
replace newcode1=440 if id==326
replace newcode1=440 if id==331
replace newcode1=232 if id==359
replace newcode1=440 if id==448
replace newcode1=730 if id==456
replace newcode1=440 if id==471
replace newcode1=224 if id==495
replace newcode1=320 if id==496
replace newcode1=222 if id==522
replace newcode1=219 if id==541
replace newcode1=730 if id==574
replace newcode1=450 if id==575
replace newcode1=321 if id==595
replace newcode1=450 if id==599


* Column 2
gen int newcode2=.
replace newcode2=490 if id==18
replace newcode2=228 if id==44
replace newcode2=238 if id==82
replace newcode2=410 if id==100
replace newcode2=240 if id==159
replace newcode2=710 if id==174
replace newcode2=240 if id==194
replace newcode2=340 if id==227
replace newcode2=590 if id==238
replace newcode2=450 if id==245
replace newcode2=490 if id==277
replace newcode2=440 if id==282
replace newcode2=210 if id==311
replace newcode2=710 if id==339
replace newcode2=240 if id==372
replace newcode2=410 if id==421
replace newcode2=238 if id==433
replace newcode2=340 if id==449
replace newcode2=232 if id==453
replace newcode2=240 if id==564
replace newcode2=520 if id==565
replace newcode2=600 if id==594
replace newcode2=130 if id==602
* Agree on 2:
replace newcode2=239 if id==40
replace newcode2=211 if id==54
replace newcode2=232 if id==83
replace newcode2=227 if id==169
replace newcode2=220 if id==185
replace newcode2=220 if id==188
replace newcode2=220 if id==247
replace newcode2=222 if id==262
replace newcode2=219 if id==344
replace newcode2=238 if id==358
replace newcode2=220 if id==387
replace newcode2=218 if id==496
* Agree on 1:
replace newcode2=440 if id==5
replace newcode2=450 if id==21
replace newcode2=228 if id==44
replace newcode2=421 if id==55
replace newcode2=227 if id==62
replace newcode2=234 if id==80
replace newcode2=440 if id==87
replace newcode2=240 if id==94
replace newcode2=450 if id==111
replace newcode2=220 if id==130
replace newcode2=730 if id==140
replace newcode2=440 if id==141
replace newcode2=440 if id==148
replace newcode2=440 if id==208
replace newcode2=450 if id==236
replace newcode2=410 if id==272
replace newcode2=420 if id==283
replace newcode2=400 if id==308
replace newcode2=720 if id==316
replace newcode2=400 if id==318
replace newcode2=440 if id==343
replace newcode2=440 if id==379
replace newcode2=221 if id==382
replace newcode2=227 if id==399
replace newcode2=450 if id==402
replace newcode2=220 if id==414
replace newcode2=238 if id==433
replace newcode2=730 if id==456
replace newcode2=440 if id==477
replace newcode2=440 if id==491
replace newcode2=338 if id==516
replace newcode2=234 if id==542
replace newcode2=730 if id==574
replace newcode2=440 if id==575
replace newcode2=440 if id==585
replace newcode2=213 if id==590
replace newcode2=130 if id==602


* Column 3
gen int newcode3=.
replace newcode3=110 if id==22
replace newcode3=720 if id==38 // Tax info
replace newcode3=400 if id==79 // Local
replace newcode3=410 if id==100
replace newcode3=440 if id==134
replace newcode3=234 if id==193
replace newcode3=234 if id==212
replace newcode3=130 if id==227
replace newcode3=720 if id==277 // Ghoasts!
replace newcode3=720 if id==311 // Outsider
replace newcode3=440 if id==339
replace newcode3=224 if id==433
replace newcode3=440 if id==453
replace newcode3=400 if id==524
replace newcode3=120 if id==555
replace newcode3=240 if id==564
replace newcode3=590 if id==565
* Agree on 2:
replace newcode3=220 if id==27
replace newcode3=219 if id==32
replace newcode3=226 if id==68
replace newcode3=239 if id==70
replace newcode3=222 if id==95 // Welfare - recode 
replace newcode3=219 if id==242
replace newcode3=224 if id==262
replace newcode3=227 if id==323
replace newcode3=227 if id==324
replace newcode3=215 if id==344
replace newcode3=239 if id==383
replace newcode3=230 if id==410 // Development
replace newcode3=222 if id==499
replace newcode3=230 if id==510
replace newcode3=233 if id==536 // Open space
* Agree on 1:
replace newcode3=440 if id==2
replace newcode3=420 if id==6
replace newcode3=110 if id==24
replace newcode3=130 if id==31
replace newcode3=500 if id==47
replace newcode3=440 if id==51
replace newcode3=230 if id==72
replace newcode3=440 if id==74
replace newcode3=720 if id==88
replace newcode3=440 if id==104
replace newcode3=440 if id==111
replace newcode3=440 if id==121
replace newcode3=430 if id==126
replace newcode3=120 if id==138
replace newcode3=239 if id==201
replace newcode3=440 if id==203
replace newcode3=440 if id==205
replace newcode3=238 if id==220
replace newcode3=120 if id==259
replace newcode3=410 if id==264
replace newcode3=230 if id==272
replace newcode3=110 if id==328
replace newcode3=230 if id==340
replace newcode3=730 if id==343
replace newcode3=237 if id==358
replace newcode3=440 if id==360
replace newcode3=338 if id==361
replace newcode3=440 if id==374
replace newcode3=230 if id==399
replace newcode3=490 if id==408
replace newcode3=730 if id==456
replace newcode3=710 if id==477
replace newcode3=490 if id==483 // Racism
replace newcode3=720 if id==559 // Church and state
replace newcode3=238 if id==567
replace newcode3=730 if id==574
replace newcode3=720 if id==577
replace newcode3=440 if id==584
replace newcode3=440 if id==599


* Column 4
gen int newcode4=.
replace newcode4=410 if id==8
replace newcode4=410 if id==17
replace newcode4=410 if id==20
replace newcode4=410 if id==25
replace newcode4=238 if id==38
replace newcode4=410 if id==43
replace newcode4=400 if id==45
replace newcode4=410 if id==79
replace newcode4=720 if id==100 // Prev. political history
replace newcode4=440 if id==108
replace newcode4=340 if id==137
replace newcode4=400 if id==159
replace newcode4=410 if id==182
replace newcode4=221 if id==227
replace newcode4=490 if id==238
replace newcode4=450 if id==282
replace newcode4=110 if id==345
replace newcode4=240 if id==372
replace newcode4=410 if id==415
replace newcode4=410 if id==429
replace newcode4=410 if id==433
replace newcode4=730 if id==453
replace newcode4=120 if id==486
replace newcode4=410 if id==505
replace newcode4=720 if id==514
replace newcode4=110 if id==563
replace newcode4=720 if id==565
replace newcode4=240 if id==594
replace newcode4=410 if id==603
* Agree on 2:
replace newcode4=220 if id==9
replace newcode4=219 if id==81
replace newcode4=110 if id==114
replace newcode4=220 if id==120
replace newcode4=210 if id==121
replace newcode4=332 if id==152
replace newcode4=224 if id==169
replace newcode4=232 if id==181
replace newcode4=212 if id==303
replace newcode4=221 if id==321
replace newcode4=219 if id==353
replace newcode4=231 if id==370
replace newcode4=219 if id==395
replace newcode4=213 if id==399
replace newcode4=220 if id==441
replace newcode4=219 if id==458
replace newcode4=220 if id==496
replace newcode4=233 if id==499
replace newcode4=219 if id==521
replace newcode4=224 if id==577
* Agree on 1:
replace newcode4=410 if id==6
replace newcode4=440 if id==26
replace newcode4=440 if id==33
replace newcode4=730 if id==37
replace newcode4=730 if id==39
replace newcode4=239 if id==40 // Campaign finance
replace newcode4=440 if id==55
replace newcode4=440 if id==60
replace newcode4=440 if id==74
replace newcode4=440 if id==104
replace newcode4=440 if id==141
replace newcode4=218 if id==201
replace newcode4=440 if id==208
replace newcode4=239 if id==226
replace newcode4=410 if id==244
replace newcode4=720 if id==287
replace newcode4=440 if id==294
replace newcode4=450 if id==310
replace newcode4=440 if id==348
replace newcode4=216 if id==350
replace newcode4=228 if id==357
replace newcode4=440 if id==367
replace newcode4=440 if id==374
replace newcode4=440 if id==389
replace newcode4=730 if id==390
replace newcode4=440 if id==404
replace newcode4=730 if id==463
replace newcode4=710 if id==470
replace newcode4=730 if id==480
replace newcode4=239 if id==484
replace newcode4=440 if id==491
replace newcode4=212 if id==507
replace newcode4=240 if id==526
replace newcode4=110 if id==545
replace newcode4=720 if id==572
replace newcode4=700 if id==574
replace newcode4=710 if id==585


* Column 5
gen int newcode5=.
replace newcode5=410 if id==10
replace newcode5=219 if id==82
replace newcode5=410 if id==100
replace newcode5=720 if id==123
replace newcode5=240 if id==174
replace newcode5=238 if id==193
replace newcode5=110 if id==194
replace newcode5=240 if id==227
replace newcode5=218 if id==240
replace newcode5=440 if id==275
replace newcode5=590 if id==277
replace newcode5=440 if id==282
replace newcode5=210 if id==311
replace newcode5=217 if id==319
replace newcode5=710 if id==345
replace newcode5=240 if id==372
replace newcode5=238 if id==421
replace newcode5=720 if id==449
replace newcode5=400 if id==453
replace newcode5=410 if id==486
replace newcode5=410 if id==513
replace newcode5=710 if id==524
replace newcode5=410 if id==539
replace newcode5=490 if id==594
* Agree on 2:
replace newcode5=228 if id==27
replace newcode5=220 if id==95
replace newcode5=222 if id==202 // Welfare
replace newcode5=216 if id==303
replace newcode5=227 if id==324
replace newcode5=229 if id==325
replace newcode5=219 if id==344
replace newcode5=214 if id==353
replace newcode5=239 if id==381
replace newcode5=219 if id==386
replace newcode5=220 if id==387
replace newcode5=220 if id==461
replace newcode5=213 if id==490
replace newcode5=225 if id==561
replace newcode5=224 if id==571

* Column 6
gen int newcode6=.
replace newcode6=237 if id==10
replace newcode6=720 if id==18 // Community 
replace newcode6=720 if id==22
replace newcode6=720 if id==44
replace newcode6=400 if id==79
replace newcode6=440 if id==134
replace newcode6=340 if id==227
replace newcode6=440 if id==228
replace newcode6=590 if id==238
replace newcode6=450 if id==271
replace newcode6=720 if id==277 // Personal ambition
replace newcode6=720 if id==311
replace newcode6=510 if id==345
replace newcode6=590 if id==421
replace newcode6=240 if id==429
replace newcode6=237 if id==449
replace newcode6=232 if id==453
replace newcode6=410 if id==539
replace newcode6=340 if id==547
replace newcode6=490 if id==564
* Agree on 2:
replace newcode6=110 if id==68
replace newcode6=210 if id==138
replace newcode6=239 if id==152
replace newcode6=231 if id==198
replace newcode6=219 if id==253
replace newcode6=219 if id==272
replace newcode6=228 if id==309
replace newcode6=219 if id==437
replace newcode6=232 if id==461
replace newcode6=210 if id==502
replace newcode6=225 if id==561
replace newcode6=224 if id==593



list id newcode1 if noagreee1==1 | agreee11==1 | agreee21==1 | check11==0
// ID 38 needs to be done
replace newcode1=238 if id==38

list id newcode2 co1_info2 jo1_info2 if noagreee2==1 | agreee12==1 | agreee22==1 | check12==0
replace newcode2=490 if id==24 // Criminal background
replace newcode2=410 if id==46
replace newcode2=710 if id==61
replace newcode2=240 if id==88
replace newcode2=430 if id==91
replace newcode2=240 if id==119
replace newcode2=490 if id==142
replace newcode2=400 if id==143
replace newcode2=218 if id==152
replace newcode2=110 if id==153
replace newcode2=720 if id==157
replace newcode2=720 if id==164
replace newcode2=400 if id==178
replace newcode2=400 if id==186
replace newcode2=400 if id==207
replace newcode2=219 if id==209
replace newcode2=410 if id==218
replace newcode2=410 if id==229
replace newcode2=720 if id==235
replace newcode2=440 if id==241
replace newcode2=410 if id==246
replace newcode2=410 if id==254
replace newcode2=710 if id==255
replace newcode2=490 if id==256
replace newcode2=410 if id==320
replace newcode2=410 if id==322
replace newcode2=410 if id==328
replace newcode2=120 if id==329
replace newcode2=720 if id==332
replace newcode2=410 if id==337
replace newcode2=710 if id==341
replace newcode2=720 if id==374
replace newcode2=450 if id==380
replace newcode2=450 if id==401
replace newcode2=720 if id==419
replace newcode2=110 if id==420
replace newcode2=410 if id==430
replace newcode2=400 if id==442
replace newcode2=240 if id==446
replace newcode2=239 if id==448
replace newcode2=340 if id==452
replace newcode2=240 if id==455
replace newcode2=410 if id==457
replace newcode2=400 if id==464
replace newcode2=410 if id==469
replace newcode2=110 if id==474
replace newcode2=410 if id==475
replace newcode2=211 if id==483
replace newcode2=240 if id==498
replace newcode2=120 if id==512
replace newcode2=400 if id==523
replace newcode2=410 if id==525
replace newcode2=130 if id==528
replace newcode2=240 if id==533
replace newcode2=240 if id==550
replace newcode2=240 if id==562
replace newcode2=410 if id==578
replace newcode2=410 if id==587
replace newcode2=720 if id==599



list id newcode3 if noagreee3==1 | agreee13==1 | agreee23==1 | check13==0
replace newcode3=490 if id==30  
replace newcode3=400 if id==36 
replace newcode3=400 if id==56
replace newcode3=110 if id==76
replace newcode3=700 if id==92
replace newcode3=400 if id==94
replace newcode3=490 if id==114
replace newcode3=720 if id==136
replace newcode3=450 if id==157
replace newcode3=410 if id==161
replace newcode3=238 if id==164
replace newcode3=410 if id==176
replace newcode3=720 if id==178
replace newcode3=237 if id==195
replace newcode3=410 if id==207
replace newcode3=590 if id==208
replace newcode3=340 if id==213
replace newcode3=337 if id==219
replace newcode3=400 if id==229
replace newcode3=400 if id==232
replace newcode3=490 if id==235
replace newcode3=450 if id==236
replace newcode3=222 if id==284
replace newcode3=120 if id==293
replace newcode3=337 if id==295
replace newcode3=410 if id==297
replace newcode3=338 if id==329
replace newcode3=710 if id==331
replace newcode3=120 if id==336
replace newcode3=410 if id==351
replace newcode3=130 if id==353
replace newcode3=410 if id==366
replace newcode3=400 if id==369
replace newcode3=217 if id==376
replace newcode3=410 if id==379
replace newcode3=710 if id==380
replace newcode3=720 if id==404
replace newcode3=490 if id==405
replace newcode3=110 if id==420
replace newcode3=430 if id==434
replace newcode3=340 if id==435
replace newcode3=120 if id==437
replace newcode3=239 if id==458
replace newcode3=233 if id==460
replace newcode3=130 if id==488
replace newcode3=410 if id==489
replace newcode3=217 if id==517
replace newcode3=720 if id==521
replace newcode3=410 if id==530
replace newcode3=720 if id==558
replace newcode3=490 if id==562
replace newcode3=340 if id==568
replace newcode3=450 if id==575
replace newcode3=110 if id==590
replace newcode3=710 if id==373

list id newcode4 if noagreee4==1 | agreee14==1 | agreee24==1 | check21==0
replace newcode4=490 if id==5
replace newcode4=410 if id==29
replace newcode4=410 if id==46
replace newcode4=490 if id==53
replace newcode4=337 if id==54
replace newcode4=710 if id==58
replace newcode4=450 if id==59
replace newcode4=400 if id==61
replace newcode4=237 if id==84
replace newcode4=410 if id==85
replace newcode4=231 if id==89
replace newcode4=410 if id==98
replace newcode4=110 if id==105
replace newcode4=410 if id==107
replace newcode4=214 if id==122
replace newcode4=410 if id==124
replace newcode4=590 if id==128
replace newcode4=720 if id==133
replace newcode4=238 if id==135
replace newcode4=600 if id==136
replace newcode4=700 if id==140
replace newcode4=410 if id==155
replace newcode4=410 if id==179
replace newcode4=340 if id==207
replace newcode4=214 if id==221
replace newcode4=400 if id==230
replace newcode4=239 if id==235
replace newcode4=410 if id==246
replace newcode4=720 if id==250
replace newcode4=490 if id==256
replace newcode4=311 if id==258
replace newcode4=314 if id==261
replace newcode4=410 if id==296
replace newcode4=239 if id==298
replace newcode4=240 if id==315
replace newcode4=710 if id==331
replace newcode4=710 if id==341
replace newcode4=120 if id==342
replace newcode4=320 if id==343
replace newcode4=219 if id==349
replace newcode4=110 if id==351
replace newcode4=410 if id==377
replace newcode4=224 if id==379
replace newcode4=730 if id==380
replace newcode4=410 if id==397
replace newcode4=720 if id==428
replace newcode4=410 if id==430
replace newcode4=240 if id==432
replace newcode4=410 if id==448
replace newcode4=410 if id==462
replace newcode4=430 if id==466
replace newcode4=219 if id==467
replace newcode4=410 if id==469
replace newcode4=238 if id==476
replace newcode4=228 if id==492
replace newcode4=240 if id==498
replace newcode4=130 if id==522
replace newcode4=224 if id==571
replace newcode4=410 if id==578
replace newcode4=410 if id==579
replace newcode4=730 if id==584
replace newcode4=700 if id==588
replace newcode4=240 if id==596



list id newcode5 if noagreee5==1 | agreee15==1 | agreee25==1 | check22==0
replace newcode5=440 if id==5
replace newcode5=440 if id==14
replace newcode5=440 if id==16
replace newcode5=730 if id==37
replace newcode5=730 if id==39
replace newcode5=410 if id==42
replace newcode5=410 if id==46
replace newcode5=450 if id==49
replace newcode5=430 if id==51
replace newcode5=421 if id==55
replace newcode5=238 if id==58
replace newcode5=400 if id==61
replace newcode5=410 if id==74
replace newcode5=700 if id==80
replace newcode5=430 if id==91
replace newcode5=338 if id==93
replace newcode5=232 if id==106
replace newcode5=490 if id==109
replace newcode5=410 if id==110
replace newcode5=338 if id==115
replace newcode5=450 if id==122
replace newcode5=130 if id==124
replace newcode5=340 if id==126
replace newcode5=590 if id==128
replace newcode5=490 if id==143 // What their money is in
replace newcode5=440 if id==148
replace newcode5=237 if id==162
replace newcode5=239 if id==163
replace newcode5=231 if id==176
replace newcode5=400 if id==178
replace newcode5=720 if id==183
replace newcode5=420 if id==199
replace newcode5=237 if id==201
replace newcode5=710 if id==209
replace newcode5=130 if id==219
replace newcode5=130 if id==221
replace newcode5=240 if id==222
replace newcode5=238 if id==226
replace newcode5=440 if id==236
replace newcode5=410 if id==242
replace newcode5=410 if id==243
replace newcode5=237 if id==250
replace newcode5=410 if id==254
replace newcode5=214 if id==258
replace newcode5=318 if id==261
replace newcode5=400 if id==268
replace newcode5=440 if id==283
replace newcode5=410 if id==301
replace newcode5=340 if id==316
replace newcode5=410 if id==320
replace newcode5=410 if id==322
replace newcode5=440 if id==331
replace newcode5=450 if id==332
replace newcode5=120 if id==336
replace newcode5=410 if id==338
replace newcode5=110 if id==342
replace newcode5=730 if id==343
replace newcode5=237 if id==349
replace newcode5=410 if id==351
replace newcode5=340 if id==355
replace newcode5=313 if id==382
replace newcode5=730 if id==390
replace newcode5=410 if id==393
replace newcode5=490 if id==402
replace newcode5=410 if id==405
replace newcode5=430 if id==406
replace newcode5=340 if id==416
replace newcode5=110 if id==420
replace newcode5=490 if id==424
replace newcode5=410 if id==432
replace newcode5=500 if id==434
replace newcode5=410 if id==443
replace newcode5=238 if id==448
replace newcode5=318 if id==452
replace newcode5=240 if id==455
replace newcode5=430 if id==459
replace newcode5=410 if id==464
replace newcode5=440 if id==471
replace newcode5=338 if id==476
replace newcode5=440 if id==477
replace newcode5=730 if id==480
replace newcode5=410 if id==487
replace newcode5=540 if id==492
replace newcode5=219 if id==507
replace newcode5=530 if id==511
replace newcode5=337 if id==517
replace newcode5=318 if id==522
replace newcode5=710 if id==523
replace newcode5=410 if id==536
replace newcode5=450 if id==538
replace newcode5=730 if id==541
replace newcode5=490 if id==542
replace newcode5=440 if id==543
replace newcode5=214 if id==550
replace newcode5=590 if id==567
replace newcode5=450 if id==574
replace newcode5=450 if id==575
replace newcode5=440 if id==581
replace newcode5=224 if id==582
replace newcode5=730 if id==584
replace newcode5=450 if id==585
replace newcode5=410 if id==587
replace newcode5=450 if id==590
replace newcode5=440 if id==599
replace newcode5=450 if id==397
replace newcode5=213 if id==224


list id newcode6 if noagreee6==1 | agreee16==1 | agreee26==1 | check23==0
replace newcode6=238 if id==1
replace newcode6=450 if id==5
replace newcode6=420 if id==6
replace newcode6=240 if id==11
replace newcode6=450 if id==12
replace newcode6=440 if id==19
replace newcode6=450 if id==21
replace newcode6=337 if id==24
replace newcode6=720 if id==36
replace newcode6=730 if id==37
replace newcode6=238 if id==39
replace newcode6=450 if id==42
replace newcode6=490 if id==46
replace newcode6=400 if id==56
replace newcode6=510 if id==59
replace newcode6=238 if id==66
replace newcode6=400 if id==76
replace newcode6=120 if id==87
replace newcode6=410 if id==93
replace newcode6=240 if id==94
replace newcode6=238 if id==98
replace newcode6=410 if id==103
replace newcode6=440 if id==104
replace newcode6=490 if id==110
replace newcode6=410 if id==114
replace newcode6=440 if id==122
replace newcode6=450 if id==126
replace newcode6=110 if id==130
replace newcode6=430 if id==132
replace newcode6=730 if id==136
replace newcode6=240 if id==142
replace newcode6=110 if id==154
replace newcode6=340 if id==157
replace newcode6=410 if id==161
replace newcode6=239 if id==172
replace newcode6=130 if id==183
replace newcode6=110 if id==186
replace newcode6=337 if id==195
replace newcode6=720 if id==203
replace newcode6=440 if id==205
replace newcode6=222 if id==210
replace newcode6=219 if id==211
replace newcode6=217 if id==217
replace newcode6=212 if id==221
replace newcode6=410 if id==229
replace newcode6=400 if id==232
replace newcode6=490 if id==241
replace newcode6=410 if id==255
replace newcode6=430 if id==256
replace newcode6=216 if id==258
replace newcode6=213 if id==261
replace newcode6=410 if id==264
replace newcode6=730 if id==269
replace newcode6=400 if id==281
replace newcode6=590 if id==283
replace newcode6=224 if id==284
replace newcode6=450 if id==289
replace newcode6=238 if id==290
replace newcode6=700 if id==292
replace newcode6=110 if id==294
replace newcode6=590 if id==301
replace newcode6=219 if id==303
replace newcode6=410 if id==306
replace newcode6=237 if id==307
replace newcode6=120 if id==336
replace newcode6=130 if id==338
replace newcode6=239 if id==340
replace newcode6=720 if id==342
replace newcode6=730 if id==343
replace newcode6=239 if id==349
replace newcode6=239 if id==359
replace newcode6=217 if id==371
replace newcode6=700 if id==374
replace newcode6=440 if id==379
replace newcode6=730 if id==380
replace newcode6=318 if id==382
replace newcode6=400 if id==384
replace newcode6=730 if id==390
replace newcode6=120 if id==391
replace newcode6=130 if id==398
replace newcode6=430 if id==405
replace newcode6=410 if id==407
replace newcode6=430 if id==408
replace newcode6=329 if id==413
replace newcode6=710 if id==419
replace newcode6=238 if id==420
replace newcode6=590 if id==421
replace newcode6=730 if id==424
replace newcode6=410 if id==425
replace newcode6=340 if id==435
replace newcode6=700 if id==443
replace newcode6=237 if id==445
replace newcode6=440 if id==446
replace newcode6=720 if id==452
replace newcode6=239 if id==458
replace newcode6=219 if id==463
replace newcode6=730 if id==480
replace newcode6=240 if id==481
replace newcode6=240 if id==485
replace newcode6=530 if id==488
replace newcode6=590 if id==500
replace newcode6=410 if id==506
replace newcode6=331 if id==507
replace newcode6=730 if id==511
replace newcode6=410 if id==516
replace newcode6=212 if id==520
replace newcode6=318 if id==522
replace newcode6=490 if id==529
replace newcode6=710 if id==533
replace newcode6=730 if id==541
replace newcode6=730 if id==551
replace newcode6=240 if id==552
replace newcode6=240 if id==562
replace newcode6=410 if id==567
replace newcode6=490 if id==575
replace newcode6=400 if id==577
replace newcode6=450 if id==578
replace newcode6=410 if id==581
replace newcode6=720 if id==582
replace newcode6=430 if id==586
replace newcode6=420 if id==588
replace newcode6=120 if id==590
replace newcode6=490 if id==592
replace newcode6=490 if id==596
replace newcode6=410 if id==598
replace newcode6=238 if id==599


***********
* Recoding the 400's, 490's and 720's

list id newcode1 if newcode1==490
replace newcode1=460 if id==238 // Criminal record
replace newcode1=340 if id==378

list id newcode2 if newcode2==490
replace newcode2=410 if id==18
replace newcode2=410 if id==24
replace newcode2=460 if id==142
replace newcode2=470 if id==256 // Military service
replace newcode2=480 if id==277 // Political Ambition/Career Politician

list id newcode3 if newcode3==490
replace newcode3=460 if id==30
replace newcode3=491 if id==235 // Cares about community
replace newcode3=460 if id==405
replace newcode3=491 if id==562

list id newcode4 if newcode4==490
replace newcode4=460 if id==53
replace newcode4=460 if id==238
replace newcode4=470 if id==256

list id newcode5 if newcode5==490
replace newcode5=491 if id==109
replace newcode5=460 if id==402
replace newcode5=460 if id==542
replace newcode5=491 if id==594

list id newcode6 if newcode6==490
replace newcode6=480 if id==241
replace newcode6=460 if id==529
replace newcode6=460 if id==592

list id newcode1 if newcode1==400
* None

list id newcode2 if newcode2==400
replace newcode2=490 if id==143
replace newcode2=560 if id==178
replace newcode2=238 if id==186
replace newcode2=560 if id==207
replace newcode2=560 if id==308
replace newcode2=560 if id==318
replace newcode2=560 if id==442
replace newcode2=560 if id==464
replace newcode2=560 if id==523

list id newcode3 if newcode3==400
replace newcode3=560 if id==79
replace newcode3=560 if id==229
replace newcode3=560 if id==369
replace newcode3=560 if id==524

list id newcode4 if newcode4==400
replace newcode4=560 if id==45
replace newcode4=560 if id==61
replace newcode4=490 if id==159
replace newcode4=560 if id==230

list id newcode5 if newcode5==400
replace newcode5=560 if id==61
replace newcode5=560 if id==178
replace newcode5=560 if id==268
replace newcode5=440 if id==453

list id newcode6 if newcode6==400 
replace newcode6=560 if id==79
replace newcode6=560 if id==281
replace newcode6=560 if id==384

list id newcode1 if newcode1==720
replace newcode1=491 if id==109
replace newcode1=491 if id==194
replace newcode1=545 if id==271 // Beliefs about religion/science
replace newcode1=491 if id==421
replace newcode1=480 if id==514

list id newcode2 if newcode2==720
replace newcode2=545 if id==157
replace newcode2=491 if id==164
replace newcode2=491 if id==235
replace newcode2=491 if id==316
replace newcode2=491 if id==332
replace newcode2=710 if id==419
replace newcode2=491 if id==599

list id newcode3 if newcode3==720
replace newcode3=215 if id==38
replace newcode3=491 if id==88
replace newcode3=480 if id==178
replace newcode3=545 if id==277
replace newcode3=480 if id==311
replace newcode3=480 if id==404
replace newcode3=491 if id==521
replace newcode3=490 if id==558
replace newcode3=110 if id==559
replace newcode3=110 if id==577

list id newcode4 if newcode4==720
replace newcode4=240 if id==100
replace newcode4=480 if id==133
replace newcode4=491 if id==250
replace newcode4=240 if id==287
replace newcode4=240 if id==428
replace newcode4=480 if id==514
replace newcode4=545 if id==565
replace newcode4=491 if id==572

list id newcode5 if newcode5==720
replace newcode5=480 if id==123
replace newcode5=480 if id==183
replace newcode5=480 if id==449

list id newcode6 if newcode6==720 
replace newcode6=491 if id==18
replace newcode6=491 if id==22
replace newcode6=491 if id==36
replace newcode6=480 if id==44
replace newcode6=480 if id==203
replace newcode6=480 if id==277
replace newcode6=480 if id==311
replace newcode6=480 if id==342
replace newcode6=480 if id==452
replace newcode6=480 if id==582

save CJCodes_recode, replace





***** PART 2: CREATING MAIN DATASET *****
*****************************************


clear all
insheet using "myk1_codes.csv", comma
drop v1
rename v2 qualtrics_id
rename v3 office_mayor_code
drop if qualtrics_id=="qualtrics_id"
save myk1_codes, replace

clear all
insheet using "Demo.csv", comma
merge 1:1 qualtrics_id using myk1_codes
keep id qualtrics_id time media_time media_trust party partydum ideology soph age sex race edu income office_mayor_type office_mayor_info office_comp_type office_comp_info office_clerk_type office_clerk_info office_judge_type office_judge_info office_gov_type office_gov_info office_pres_type office_pres_info office_mayor_code
save Demo, replace
merge 1:1 id using CJCodes_recode, nogenerate // No issues with merge - all rows merged
drop cv18 cv19 cv20
drop if id==313
destring media_time media_trust party partydum ideology soph age sex race edu income co1_type co1_info1 co1_info2 co1_info3 co1_tallym co1_tallyf co1_tallyn co1_know co2_type co2_info2 co2_info3 co2_tallym co2_tallyf co2_tallyn co2_know jo1_type, replace i("NA")
mvencode *, mv(999)
replace co2_know=0 if co2_know==999
replace jo2_know=0 if jo2_know==999
replace co2_tallyn=0 if co2_tallyn==999

mvdecode id-newcode6, mv(999)
drop if id==.

replace newcode1 = co1_info1 if newcode1 ==.
replace newcode2 = co1_info2 if newcode2 ==.
replace newcode3 = co1_info3 if newcode3 ==.
replace newcode4 = co2_info1 if newcode4 ==.
replace newcode5 = co2_info2 if newcode5 ==.
replace newcode6 = co2_info3 if newcode6 ==.

drop co1_type-co1_info3
drop co2_type-co2_info3
drop jo1_info1-jo1_info3
drop jo2_info1-jo2_info3
drop check11-rowagreee0

rename newcode1 o1_info1
rename newcode2 o1_info2
rename newcode3 o1_info3
rename newcode4 o2_info1
rename newcode5 o2_info2
rename newcode6 o2_info3
rename jo1_type o1_type
rename jo2_type o2_type

g o1_know = (jo1_know + co1_know)/2
replace o1_know = 1 if o1_know ==1.5
g o2_know = (jo2_know + co2_know)/2

drop co1_know
drop co2_know
drop jo1_know
drop jo2_know

rename office_mayor_code mayorcondition

replace o1_type =4 if id==483
replace o1_type =6 if id==322

g mayor_info1 = o1_info1 if o1_type==1
replace mayor_info1 = o2_info1 if o2_type==1
g mayor_info2 = o1_info2 if o1_type==1
replace mayor_info2 = o2_info2 if o2_type==1
g mayor_info3 = o1_info3 if o1_type==1
replace mayor_info3 = o2_info3 if o2_type==1
g mayor_know = o1_know if o1_type==1
replace mayor_know = o2_know if o2_type==1

g gov_info1 = o1_info1 if o1_type==2
replace gov_info1 = o2_info1 if o2_type==2
g gov_info2 = o1_info2 if o1_type==2
replace gov_info2 = o2_info2 if o2_type==2
g gov_info3 = o1_info3 if o1_type==2
replace gov_info3 = o2_info3 if o2_type==2
g gov_know = o1_know if o1_type==2
replace gov_know = o2_know if o2_type==2

g pres_info1 = o1_info1 if o1_type==3
replace pres_info1 = o2_info1 if o2_type==3
g pres_info2 = o1_info2 if o1_type==3
replace pres_info2 = o2_info2 if o2_type==3
g pres_info3 = o1_info3 if o1_type==3
replace pres_info3 = o2_info3 if o2_type==3
g pres_know = o1_know if o1_type==3
replace pres_know = o2_know if o2_type==3

g clerk_info1 = o1_info1 if o1_type==4
replace clerk_info1 = o2_info1 if o2_type==4
g clerk_info2 = o1_info2 if o1_type==4
replace clerk_info2 = o2_info2 if o2_type==4
g clerk_info3 = o1_info3 if o1_type==4
replace clerk_info3 = o2_info3 if o2_type==4
g clerk_know = o1_know if o1_type==4
replace clerk_know = o2_know if o2_type==4

g comp_info1 = o1_info1 if o1_type==5
replace comp_info1 = o2_info1 if o2_type==5
g comp_info2 = o1_info2 if o1_type==5
replace comp_info2 = o2_info2 if o2_type==5
g comp_info3 = o1_info3 if o1_type==5
replace comp_info3 = o2_info3 if o2_type==5
g comp_know = o1_know if o1_type==5
replace comp_know = o2_know if o2_type==5

g judge_info1 = o1_info1 if o1_type==6
replace judge_info1 = o2_info1 if o2_type==6
g judge_info2 = o1_info2 if o1_type==6
replace judge_info2 = o2_info2 if o2_type==6
g judge_info3 = o1_info3 if o1_type==6
replace judge_info3 = o2_info3 if o2_type==6
g judge_know = o1_know if o1_type==6
replace judge_know = o2_know if o2_type==6

g o1_atttype = office_mayor_type if o1_type==1
replace o1_atttype = office_gov_type if o1_type==2
replace o1_atttype = office_pres_type if o1_type==3
replace o1_atttype = office_clerk_type if o1_type==4
replace o1_atttype = office_comp_type if o1_type==5
replace o1_atttype = office_judge_type if o1_type==6

g o1_att = office_mayor_info if o1_type==1
replace o1_att = office_gov_info if o1_type==2
replace o1_att = office_pres_info if o1_type==3
replace o1_att = office_clerk_info if o1_type==4
replace o1_att = office_comp_info if o1_type==5
replace o1_att = office_judge_info if o1_type==6

g o2_atttype = office_mayor_type if o2_type==1
replace o2_atttype = office_gov_type if o2_type==2
replace o2_atttype = office_pres_type if o2_type==3
replace o2_atttype = office_clerk_type if o2_type==4
replace o2_atttype = office_comp_type if o2_type==5
replace o2_atttype = office_judge_type if o2_type==6

g o2_att = office_mayor_info if o2_type==1
replace o2_att = office_gov_info if o2_type==2
replace o2_att = office_pres_info if o2_type==3
replace o2_att = office_clerk_info if o2_type==4
replace o2_att = office_comp_info if o2_type==5
replace o2_att = office_judge_info if o2_type==6

for any mayor gov pres clerk comp judge: rename office_X_type office_X_atttype
for any mayor gov pres clerk comp judge: rename office_X_info office_X_att

merge 1:1 qualtrics_id using tmyk1_mediatype, nogenerate 


expand 2

g o_type = o1_type if _n<604
replace o_type = o2_type if _n>603
g o_info1 = o1_info1 if _n<604
replace o_info1 = o2_info1 if _n>603
g o_info2 = o1_info2 if _n<604
replace o_info2 = o2_info2 if _n>603
g o_info3 = o1_info3 if _n<604
replace o_info3 = o2_info3 if _n>603
g o_know = o1_know if _n<604
replace o_know = o2_know if _n>603
g o_atttype = o1_atttype if _n<604
replace o_atttype = o2_atttype if _n>603
g o_att = o1_att if _n<604
replace o_att = o2_att if _n>603
g c_tallym = co1_tallym if _n<604
replace c_tallym = co2_tallym if _n>603
g c_tallyf = co1_tallyf if _n<604
replace c_tallyf = co2_tallyf if _n>603
g c_tallyn = co1_tallyn if _n<604
replace c_tallyn = co2_tallyn if _n>603
g j_tallym = jo1_tallym if _n<604
replace j_tallym = jo2_tallym if _n>603
g j_tallyf = jo1_tallyf if _n<604
replace j_tallyf = jo2_tallyf if _n>603
g j_tallyn = jo1_tallyn if _n<604
replace j_tallyn = jo2_tallyn if _n>603


expand 2
expand 2
drop if _n>3618
g o_allinfo = o_info1 if _n<604
replace o_allinfo = o_info1 if _n>603 & _n<1207
replace o_allinfo = o_info2 if _n>1206 & _n<1810
replace o_allinfo = o_info2 if _n>1809 & _n<2413
replace o_allinfo = o_info3 if _n>2412 & _n<3016
replace o_allinfo = o_info3 if _n>3015 

g o_info1_simple = int(o_info1/100)
g o_info2_simple = int(o_info2/100)
g o_info3_simple = int(o_info3/100)
g o_allinfo_simple = int(o_allinfo/100)
for any mayor gov pres clerk comp judge: g X_info1_simple = int(X_info1/100)
for any mayor gov pres clerk comp judge: g X_info2_simple = int(X_info2/100)
for any mayor gov pres clerk comp judge: g X_info3_simple = int(X_info3/100)

g o_info1_specpolicy =(o_info1_simple==2|o_info1_simple==3) & o_info1!=240 & o_info1!=340
replace o_info1_specpolicy =2 if o_info1==240|o_info1==340
g o_info2_specpolicy =(o_info2_simple==2|o_info2_simple==3) & o_info2!=240 & o_info2!=340
replace o_info2_specpolicy =2 if o_info2==240|o_info2==340
g o_info3_specpolicy =(o_info3_simple==2|o_info3_simple==3) & o_info3!=240 & o_info3!=340
replace o_info3_specpolicy =2 if o_info3==240|o_info3==340

destring *, replace i("NA")

mvdecode office_mayor_atttype-office_pres_att if _n>603, mv(0/1000)
mvdecode office_mayor_atttype-office_pres_att if _n>603, mv(0.5)
mvdecode co1_tallym-o2_att if _n>603, mv(0/1000)
mvdecode co1_tallym-o2_att if _n>603, mv(0.5)

for any mayor gov pres clerk comp judge: rename office_X_atttype X_atttype
for any mayor gov pres clerk comp judge: rename office_X_att X_att

label variable mayorcondition "1=open 2=incumbent 3=challenger 4=bf 5=bm 6=wf 7=wm"
label variable o_type "1=mayor 2=gov 3=pres 4=clerk 5=comp 6=judge"
label variable o_atttype "1=info1 disappointing 2=info3 disappointing 3=info1 encouraging 4=info2 encouraging"
label variable o_att "1=certain 2=very 3=somewhat 4=slightly 5=no change"
label variable age "1=18-25 2=26-34 3=35-54 4=55-64 5=65+"
label variable sex "1=m 2=f 3=other/declined"
label variable race "1=white 2=black 3=latino 4=asian 5=native 6=islander 7=other"
label variable edu "1=less HS 2=HS 3=some coll 4=AA 5=BA 6=MA 7=PhD 8=Prof"
label variable income "1=under 30k 2-8=10k increments 9=over 100k"

g extreme = 0 if ideology==4|ideology==8
replace extreme = 1 if ideology==3|ideology==5
replace extreme = 2 if ideology==2|ideology==6
replace extreme = 3 if ideology==1|ideology==7

label variable extreme "0-3, with ideological extremity increasing"

g ideodum = 1 if ideology==1|ideology==2|ideology==3
replace ideodum = 2 if ideology==5|ideology==6|ideology==7
replace ideodum = 3 if ideology==4

label variable ideodum "1=liberal 2=conservative 3=mod/DK"

g edsimple = 1 if edu==1|edu==2
replace edsimple = 2 if edu==3|edu==4
replace edsimple = 3 if edu==5
replace edsimple = 4 if edu>5

label variable edsimple "1=HS or less, 2=some college or AA, 3=bachelors, 4=MA, PhD, Professional"

g sophsimple = 1 if soph==0|soph==1
replace sophsimple = 2 if soph==2|soph==3
replace sophsimple = 3 if soph==4|soph==5

label variable sophsimple "soph with each bin corresponding to two scale values, three bins total"

g know = o_know==1|o_know==0.5

label variable know "1=if office knowledge is 1 from either coder, 0 otherwise"

g race_minority = race!=1

label variable race_minority "1=if minority, 0 otherwise"

g incomesimple = 1 if income==1
replace incomesimple = 2 if income==2|income==3
replace incomesimple = 3 if income==4|income==5|income==6
replace incomesimple = 4 if income==7|income==8|income==9

label variable incomesimple "1=under 30k 2=30-50k 3=50-80k 4=over 80k"

keep id qualtrics_id time party partydum ideology ideodum extreme soph sophsimple age sex race edu edsimple income incomesimple media_time media_trust media_type o_type o_info1 o_info1_simple o_info2 o_info2_simple o_info3 o_info3_simple o_allinfo o_allinfo_simple o_info1_specpolicy o_info2_specpolicy o_info3_specpolicy o_know know  o_atttype o_att mayorcondition c_tallym c_tallyf c_tallyn j_tallym j_tallyf j_tallyn 
order id qualtrics_id time party partydum ideology ideodum extreme soph sophsimple age sex race edu edsimple income incomesimple media_time media_trust media_type o_type o_info1 o_info1_simple o_info2 o_info2_simple o_info3 o_info3_simple o_allinfo o_allinfo_simple o_know know  o_atttype o_att mayorcondition c_tallym c_tallyf c_tallyn j_tallym j_tallyf j_tallyn

save CJCodes_full, replace












************************************************
******* GENERATING DATASET FOR 2ND STUDY *******
************************************************


***** PART 1: CODING RESPONSES *****
************************************

set more off
set matsize 4000 


***** Combine Julia and Rikio's codings
clear all
insheet using "Julia_TMYK2.csv", comma
replace info1 = 730 in 990
drop if id==.
rename * j= 
rename jid id
save julia, replace

clear all
insheet using "Rikio_TMYK2.csv", comma
rename * r= 
rename rid id
save rikio, replace

clear all
use julia, clear
merge 1:1 id using rikio, nogenerate // No issues with merge - all rows merged

reshape long jinfo rinfo, i(id)
order rinfo, after(jinfo)
gen fullagree= jinfo==rinfo 

tostring jinfo rinfo, replace

gen fullcatagree= substr(jinfo, 1, 2)==substr(rinfo, 1, 2) 
replace fullcatagree=. if fullagree==1

gen catagree= substr(jinfo, 1, 1)==substr(rinfo, 1, 1) 
replace catagree=. if fullagree==1 | fullcatagree==1

gen noagree= fullagree~=1 & fullcatagree~=1 & catagree~=1
replace noagree=. if fullagree==1 | fullcatagree==1 | catagree==1

gen levelagree=3 if fullagree==1
replace levelagree=2 if fullcatagree==1
replace levelagree=1 if catagree==1
replace levelagree=0 if noagree==1

order levelagree, after(rinfo)

destring jinfo rinfo, replace

gen recode=""
order recode, after(levelagree)

sort levelagree _j id

save combined_codes, replace

*** using code resolution set ***
use combined_codes, clear

clonevar jstring = jinfo
clonevar rstring = rinfo
tostring jstring rstring, replace

**** Generate code resolution

* Agree on 2
list id if levelagree==2

replace recode="220" if _j==1 & id==70
replace recode="220" if _j==1 & id==71
replace recode="220" if _j==1 & id==72
replace recode="219" if _j==1 & id==109
replace recode="420" if _j==1 & id==113
replace recode="220" if _j==1 & id==486
replace recode="730" if _j==1 & id==569
replace recode="220" if _j==1 & id==596
replace recode="220" if _j==1 & id==744
replace recode="221" if _j==1 & id==764
replace recode="221" if _j==1 & id==782
replace recode="560" if _j==1 & id==803
replace recode="560" if _j==1 & id==858
replace recode="540" if _j==1 & id==896
replace recode="238" if _j==1 & id==908
replace recode="450" if _j==1 & id==941
replace recode="240" if _j==1 & id==946
replace recode="229" if _j==1 & id==964
replace recode="440" if _j==1 & id==1103
replace recode="491" if _j==1 & id==1148
replace recode="214" if _j==1 & id==1215
replace recode="219" if _j==1 & id==1265

replace recode="234" if _j==2 & id==55
replace recode="220" if _j==2 & id==71
replace recode="222" if _j==2 & id==92
replace recode="219" if _j==2 & id==95
replace recode="222" if _j==2 & id==109
replace recode="222" if _j==2 & id==115
replace recode="228" if _j==2 & id==128
replace recode="222" if _j==2 & id==228
replace recode="217" if _j==2 & id==237
replace recode="237" if _j==2 & id==481
replace recode="730" if _j==2 & id==569
replace recode="560" if _j==2 & id==687
replace recode="220" if _j==2 & id==737
replace recode="560" if _j==2 & id==809
replace recode="240" if _j==2 & id==836
replace recode="560" if _j==2 & id==845
replace recode="560" if _j==2 & id==846
replace recode="560" if _j==2 & id==870
replace recode="221" if _j==2 & id==874
replace recode="560" if _j==2 & id==935
replace recode="219" if _j==2 & id==1080
replace recode="540" if _j==2 & id==1215
replace recode="540" if _j==2 & id==1238
replace recode="240" if _j==2 & id==1242

replace recode="234" if _j==3 & id==13
replace recode="210" if _j==3 & id==22
replace recode="490" if _j==3 & id==26
replace recode="213" if _j==3 & id==56
replace recode="220" if _j==3 & id==71
replace recode="540" if _j==3 & id==85
replace recode="234" if _j==3 & id==96
replace recode="214" if _j==3 & id==147
replace recode="491" if _j==3 & id==173
replace recode="227" if _j==3 & id==200
replace recode="211" if _j==3 & id==226
replace recode="227" if _j==3 & id==228
replace recode="222" if _j==3 & id==267
replace recode="218" if _j==3 & id==274
replace recode="217" if _j==3 & id==321
replace recode="224" if _j==3 & id==338
replace recode="217" if _j==3 & id==367
replace recode="340" if _j==3 & id==480
replace recode="233" if _j==3 & id==533
replace recode="730" if _j==3 & id==569
replace recode="560" if _j==3 & id==713
replace recode="560" if _j==3 & id==715
replace recode="229" if _j==3 & id==810
replace recode="560" if _j==3 & id==831
replace recode="560" if _j==3 & id==840
replace recode="560" if _j==3 & id==858
replace recode="560" if _j==3 & id==876
replace recode="560" if _j==3 & id==884
replace recode="560" if _j==3 & id==886
replace recode="560" if _j==3 & id==950
replace recode="211" if _j==3 & id==1015
replace recode="560" if _j==3 & id==1058
replace recode="450" if _j==3 & id==1102
replace recode="421" if _j==3 & id==1138
replace recode="540" if _j==3 & id==1166
replace recode="421" if _j==3 & id==1169
replace recode="219" if _j==3 & id==1259
replace recode="228" if _j==3 & id==1272
replace recode="540" if _j==3 & id==1291
replace recode="214" if _j==3 & id==1297

* Agree on 1:
list id if levelagree==1

replace recode="237" if _j==1 & id==3
replace recode="730" if _j==1 & id==7
replace recode="440" if _j==1 & id==12
replace recode="110" if _j==1 & id==18
replace recode="238" if _j==1 & id==31
replace recode="440" if _j==1 & id==36
replace recode="240" if _j==1 & id==47
replace recode="730" if _j==1 & id==48
replace recode="480" if _j==1 & id==63
replace recode="560" if _j==1 & id==64
replace recode="450" if _j==1 & id==67
replace recode="730" if _j==1 & id==74
replace recode="440" if _j==1 & id==77
replace recode="240" if _j==1 & id==82
replace recode="440" if _j==1 & id==87
replace recode="440" if _j==1 & id==88
replace recode="440" if _j==1 & id==89
replace recode="240" if _j==1 & id==91
replace recode="450" if _j==1 & id==93
replace recode="491" if _j==1 & id==94
replace recode="229" if _j==1 & id==97
replace recode="730" if _j==1 & id==102
replace recode="450" if _j==1 & id==107
replace recode="240" if _j==1 & id==117
replace recode="730" if _j==1 & id==119
replace recode="122" if _j==1 & id==120
replace recode="240" if _j==1 & id==122
replace recode="450" if _j==1 & id==127

* Stopped to remove all 7-series disagreements

list id jstring rstring if levelagree<=1 & substr(jstring, 1, 1)==substr(rstring, 1, 1) & substr(jstring,1,1)=="7"
replace recode="730" if levelagree<=1 & substr(jstring, 1, 1)==substr(rstring, 1, 1) & substr(jstring,1,1)=="7"
replace levelagree=7 if levelagree<=1 & substr(jstring, 1, 1)==substr(rstring, 1, 1) & substr(jstring,1,1)=="7"

replace recode="450" if _j==1 & id==139
replace recode="450" if _j==1 & id==140
replace recode="410" if _j==1 & id==142
replace recode="440" if _j==1 & id==145
replace recode="240" if _j==1 & id==163
replace recode="480" if _j==1 & id==182
replace recode="480" if _j==1 & id==190
replace recode="480" if _j==1 & id==198
replace recode="234" if _j==1 & id==203
replace recode="240" if _j==1 & id==204
replace recode="410" if _j==1 & id==205
replace recode="730" if _j==1 & id==206
replace recode="240" if _j==1 & id==207
replace recode="590" if _j==1 & id==218
replace recode="240" if _j==1 & id==229
replace recode="410" if _j==1 & id==230
replace recode="490" if _j==1 & id==233
replace recode="450" if _j==1 & id==234
replace recode="480" if _j==1 & id==235
replace recode="590" if _j==1 & id==239
replace recode="220" if _j==1 & id==242
replace recode="240" if _j==1 & id==247
replace recode="110" if _j==1 & id==248
replace recode="410" if _j==1 & id==254
replace recode="240" if _j==1 & id==259
replace recode="240" if _j==1 & id==263
replace recode="240" if _j==1 & id==266
replace recode="440" if _j==1 & id==269
replace recode="450" if _j==1 & id==275
replace recode="450" if _j==1 & id==276
replace recode="217" if _j==1 & id==284
replace recode="240" if _j==1 & id==287
replace recode="410" if _j==1 & id==288
replace recode="410" if _j==1 & id==295
replace recode="240" if _j==1 & id==303
replace recode="240" if _j==1 & id==306
replace recode="490" if _j==1 & id==312
replace recode="440" if _j==1 & id==321
replace recode="491" if _j==1 & id==322
replace recode="410" if _j==1 & id==323
replace recode="410" if _j==1 & id==334
replace recode="440" if _j==1 & id==337
replace recode="130" if _j==1 & id==356
replace recode="410" if _j==1 & id==360
replace recode="730" if _j==1 & id==364
replace recode="440" if _j==1 & id==376
replace recode="410" if _j==1 & id==378
replace recode="430" if _j==1 & id==386
replace recode="410" if _j==1 & id==406
replace recode="410" if _j==1 & id==407
replace recode="410" if _j==1 & id==408
replace recode="410" if _j==1 & id==414
replace recode="130" if _j==1 & id==431
replace recode="130" if _j==1 & id==432
replace recode="440" if _j==1 & id==437
replace recode="440" if _j==1 & id==438
replace recode="440" if _j==1 & id==439
replace recode="440" if _j==1 & id==440
replace recode="440" if _j==1 & id==441
replace recode="440" if _j==1 & id==442
replace recode="440" if _j==1 & id==443
replace recode="440" if _j==1 & id==444
replace recode="440" if _j==1 & id==445
replace recode="450" if _j==1 & id==449
replace recode="410" if _j==1 & id==451
replace recode="410" if _j==1 & id==469
replace recode="560" if _j==1 & id==484
replace recode="240" if _j==1 & id==488
replace recode="730" if _j==1 & id==491
replace recode="410" if _j==1 & id==528
replace recode="410" if _j==1 & id==542
replace recode="410" if _j==1 & id==546
replace recode="410" if _j==1 & id==556
replace recode="410" if _j==1 & id==557
replace recode="410" if _j==1 & id==562
replace recode="440" if _j==1 & id==567
replace recode="720" if _j==1 & id==573
replace recode="410" if _j==1 & id==579
replace recode="240" if _j==1 & id==586
replace recode="410" if _j==1 & id==588
replace recode="720" if _j==1 & id==597
replace recode="450" if _j==1 & id==599
replace recode="240" if _j==1 & id==602
replace recode="240" if _j==1 & id==607
replace recode="240" if _j==1 & id==612
replace recode="450" if _j==1 & id==619
replace recode="450" if _j==1 & id==621
replace recode="440" if _j==1 & id==624
replace recode="480" if _j==1 & id==633
replace recode="240" if _j==1 & id==634
replace recode="410" if _j==1 & id==638
replace recode="240" if _j==1 & id==641
replace recode="560" if _j==1 & id==642
replace recode="410" if _j==1 & id==643
replace recode="410" if _j==1 & id==654
replace recode="240" if _j==1 & id==660
replace recode="430" if _j==1 & id==663
replace recode="430" if _j==1 & id==664
replace recode="410" if _j==1 & id==666
replace recode="410" if _j==1 & id==668
replace recode="238" if _j==1 & id==674
replace recode="234" if _j==1 & id==675
replace recode="720" if _j==1 & id==684
replace recode="440" if _j==1 & id==695
replace recode="450" if _j==1 & id==698
replace recode="410" if _j==1 & id==700
replace recode="410" if _j==1 & id==715
replace recode="440" if _j==1 & id==750
replace recode="440" if _j==1 & id==751
replace recode="440" if _j==1 & id==752
replace recode="440" if _j==1 & id==753
replace recode="440" if _j==1 & id==754
replace recode="440" if _j==1 & id==755
replace recode="440" if _j==1 & id==756
replace recode="440" if _j==1 & id==757
replace recode="440" if _j==1 & id==758
replace recode="440" if _j==1 & id==759
replace recode="410" if _j==1 & id==761
replace recode="239" if _j==1 & id==767
replace recode="232" if _j==1 & id==768
replace recode="240" if _j==1 & id==783
replace recode="480" if _j==1 & id==786
replace recode="240" if _j==1 & id==787
replace recode="240" if _j==1 & id==790
replace recode="340" if _j==1 & id==802
replace recode="440" if _j==1 & id==806
replace recode="440" if _j==1 & id==807
replace recode="480" if _j==1 & id==809
replace recode="440" if _j==1 & id==855
replace recode="480" if _j==1 & id==868
replace recode="233" if _j==1 & id==869
replace recode="410" if _j==1 & id==889
replace recode="410" if _j==1 & id==890
replace recode="410" if _j==1 & id==891
replace recode="410" if _j==1 & id==892
replace recode="110" if _j==1 & id==906
replace recode="450" if _j==1 & id==910
replace recode="410" if _j==1 & id==911
replace recode="410" if _j==1 & id==916
replace recode="590" if _j==1 & id==923
replace recode="410" if _j==1 & id==926
replace recode="410" if _j==1 & id==927
replace recode="480" if _j==1 & id==928
replace recode="590" if _j==1 & id==929
replace recode="440" if _j==1 & id==938
replace recode="410" if _j==1 & id==942
replace recode="710" if _j==1 & id==945
replace recode="240" if _j==1 & id==947
replace recode="410" if _j==1 & id==950
replace recode="240" if _j==1 & id==956
replace recode="240" if _j==1 & id==959
replace recode="450" if _j==1 & id==974
replace recode="240" if _j==1 & id==976
replace recode="240" if _j==1 & id==985
replace recode="440" if _j==1 & id==991
replace recode="240" if _j==1 & id==994
replace recode="110" if _j==1 & id==998
replace recode="480" if _j==1 & id==1002
replace recode="440" if _j==1 & id==1004
replace recode="237" if _j==1 & id==1009
replace recode="460" if _j==1 & id==1012
replace recode="410" if _j==1 & id==1018
replace recode="440" if _j==1 & id==1021
replace recode="440" if _j==1 & id==1044
replace recode="440" if _j==1 & id==1045
replace recode="450" if _j==1 & id==1059
replace recode="239" if _j==1 & id==1061
replace recode="440" if _j==1 & id==1066
replace recode="440" if _j==1 & id==1067
replace recode="440" if _j==1 & id==1068
replace recode="440" if _j==1 & id==1069
replace recode="440" if _j==1 & id==1070
replace recode="440" if _j==1 & id==1071
replace recode="410" if _j==1 & id==1072
replace recode="450" if _j==1 & id==1075
replace recode="410" if _j==1 & id==1084
replace recode="240" if _j==1 & id==1098
replace recode="340" if _j==1 & id==1100
replace recode="340" if _j==1 & id==1112
replace recode="219" if _j==1 & id==1113
replace recode="450" if _j==1 & id==1117
replace recode="340" if _j==1 & id==1118
replace recode="440" if _j==1 & id==1120
replace recode="237" if _j==1 & id==1123
replace recode="440" if _j==1 & id==1124
replace recode="410" if _j==1 & id==1126
replace recode="240" if _j==1 & id==1128
replace recode="440" if _j==1 & id==1136
replace recode="410" if _j==1 & id==1139
replace recode="450" if _j==1 & id==1150
replace recode="450" if _j==1 & id==1152
replace recode="440" if _j==1 & id==1188
replace recode="240" if _j==1 & id==1189
replace recode="110" if _j==1 & id==1191
replace recode="231" if _j==1 & id==1217
replace recode="239" if _j==1 & id==1218
replace recode="710" if _j==1 & id==1234
replace recode="410" if _j==1 & id==1235
replace recode="440" if _j==1 & id==1247
replace recode="240" if _j==1 & id==1250
replace recode="450" if _j==1 & id==1266
replace recode="340" if _j==1 & id==1268
replace recode="450" if _j==1 & id==1270
replace recode="440" if _j==1 & id==1271
replace recode="440" if _j==1 & id==1274
replace recode="440" if _j==1 & id==1275
replace recode="440" if _j==1 & id==1276
replace recode="240" if _j==1 & id==1303
replace recode="240" if _j==1 & id==1305
replace recode="240" if _j==1 & id==1307



list id if levelagree==1

replace recode="410" if _j==2 & id==10
replace recode="440" if _j==2 & id==11
replace recode="240" if _j==2 & id==16
replace recode="491" if _j==2 & id==23
replace recode="240" if _j==2 & id==24
replace recode="227" if _j==2 & id==27
replace recode="240" if _j==2 & id==32
replace recode="480" if _j==2 & id==38
replace recode="240" if _j==2 & id==40
replace recode="710" if _j==2 & id==46
replace recode="240" if _j==2 & id==49
replace recode="240" if _j==2 & id==57

* Change Julia's 200's to 240's
list id jstring rstring if levelagree<=1 & substr(rstring, 1, 3)=="240" & substr(jstring,1,3)=="200"
replace recode="240" if levelagree<=1 & substr(rstring, 1, 3)=="240" & substr(jstring,1,3)=="200"
replace levelagree=20 if levelagree<=1 & substr(rstring, 1, 3)=="240" & substr(jstring,1,3)=="200"

replace recode="440" if _j==2 & id==65
replace recode="440" if _j==2 & id==67
replace recode="110" if _j==2 & id==72
replace recode="490" if _j==2 & id==76
replace recode="440" if _j==2 & id==78
replace recode="440" if _j==2 & id==80
replace recode="440" if _j==2 & id==84
replace recode="450" if _j==2 & id==86
replace recode="480" if _j==2 & id==91
replace recode="450" if _j==2 & id==93
replace recode="440" if _j==2 & id==101
replace recode="440" if _j==2 & id==110
replace recode="440" if _j==2 & id==114
replace recode="491" if _j==2 & id==116
replace recode="219" if _j==2 & id==118
replace recode="440" if _j==2 & id==127
replace recode="440" if _j==2 & id==131
replace recode="440" if _j==2 & id==139
replace recode="460" if _j==2 & id==142 // Free of public scandals
replace recode="480" if _j==2 & id==144
replace recode="232" if _j==2 & id==146
replace recode="240" if _j==2 & id==179
replace recode="590" if _j==2 & id==180
replace recode="440" if _j==2 & id==181
replace recode="480" if _j==2 & id==191
replace recode="720" if _j==2 & id==193
replace recode="239" if _j==2 & id==194
replace recode="440" if _j==2 & id==213
replace recode="219" if _j==2 & id==215
replace recode="480" if _j==2 & id==224
replace recode="450" if _j==2 & id==236
replace recode="240" if _j==2 & id==246
replace recode="480" if _j==2 & id==247
replace recode="224" if _j==2 & id==261
replace recode="228" if _j==2 & id==268
replace recode="410" if _j==2 & id==298
replace recode="590" if _j==2 & id==300
replace recode="480" if _j==2 & id==302
replace recode="224" if _j==2 & id==319
replace recode="410" if _j==2 & id==322
replace recode="410" if _j==2 & id==323
replace recode="410" if _j==2 & id==324
replace recode="440" if _j==2 & id==332
replace recode="490" if _j==2 & id==348
replace recode="490" if _j==2 & id==356
replace recode="440" if _j==2 & id==366
replace recode="130" if _j==2 & id==368
replace recode="410" if _j==2 & id==374
replace recode="480" if _j==2 & id==376
replace recode="130" if _j==2 & id==377
replace recode="720" if _j==2 & id==387
replace recode="440" if _j==2 & id==399
replace recode="440" if _j==2 & id==402
replace recode="450" if _j==2 & id==403
replace recode="410" if _j==2 & id==407
replace recode="110" if _j==2 & id==409
replace recode="410" if _j==2 & id==414
replace recode="130" if _j==2 & id==430
replace recode="130" if _j==2 & id==434
replace recode="440" if _j==2 & id==443
replace recode="490" if _j==2 & id==444
replace recode="130" if _j==2 & id==447
replace recode="110" if _j==2 & id==455
replace recode="440" if _j==2 & id==462
replace recode="110" if _j==2 & id==463
replace recode="590" if _j==2 & id==471
replace recode="130" if _j==2 & id==472
replace recode="130" if _j==2 & id==474
replace recode="440" if _j==2 & id==479
replace recode="720" if _j==2 & id==488
replace recode="440" if _j==2 & id==494
replace recode="440" if _j==2 & id==499
replace recode="410" if _j==2 & id==522
replace recode="410" if _j==2 & id==525
replace recode="480" if _j==2 & id==538
replace recode="410" if _j==2 & id==549
replace recode="410" if _j==2 & id==573
replace recode="440" if _j==2 & id==579
replace recode="110" if _j==2 & id==598
replace recode="240" if _j==2 & id==600
replace recode="410" if _j==2 & id==604
replace recode="480" if _j==2 & id==606
replace recode="440" if _j==2 & id==619
replace recode="440" if _j==2 & id==624
replace recode="440" if _j==2 & id==666
replace recode="410" if _j==2 & id==667
replace recode="450" if _j==2 & id==671
replace recode="440" if _j==2 & id==684
replace recode="480" if _j==2 & id==703
replace recode="460" if _j==2 & id==715
replace recode="440" if _j==2 & id==721
replace recode="440" if _j==2 & id==722
replace recode="440" if _j==2 & id==723
replace recode="440" if _j==2 & id==724
replace recode="440" if _j==2 & id==738
replace recode="440" if _j==2 & id==748
replace recode="460" if _j==2 & id==758
replace recode="590" if _j==2 & id==759
replace recode="450" if _j==2 & id==760
replace recode="460" if _j==2 & id==777
replace recode="720" if _j==2 & id==802
replace recode="480" if _j==2 & id==803
replace recode="490" if _j==2 & id==805
replace recode="440" if _j==2 & id==807
replace recode="410" if _j==2 & id==813
replace recode="480" if _j==2 & id==828
replace recode="440" if _j==2 & id==831
replace recode="440" if _j==2 & id==847
replace recode="410" if _j==2 & id==850
replace recode="480" if _j==2 & id==852
replace recode="720" if _j==2 & id==853
replace recode="410" if _j==2 & id==855
replace recode="219" if _j==2 & id==868
replace recode="110" if _j==2 & id==873
replace recode="410" if _j==2 & id==887
replace recode="410" if _j==2 & id==892
replace recode="440" if _j==2 & id==894
replace recode="480" if _j==2 & id==900
replace recode="240" if _j==2 & id==904
replace recode="110" if _j==2 & id==906
replace recode="450" if _j==2 & id==908
replace recode="440" if _j==2 & id==910
replace recode="410" if _j==2 & id==924
replace recode="410" if _j==2 & id==925
replace recode="440" if _j==2 & id==926
replace recode="480" if _j==2 & id==932
replace recode="440" if _j==2 & id==944
replace recode="410" if _j==2 & id==946
replace recode="440" if _j==2 & id==949
replace recode="450" if _j==2 & id==953
replace recode="440" if _j==2 & id==954
replace recode="237" if _j==2 & id==960
replace recode="440" if _j==2 & id==976
replace recode="110" if _j==2 & id==978
replace recode="480" if _j==2 & id==980
replace recode="440" if _j==2 & id==985
replace recode="440" if _j==2 & id==987
replace recode="219" if _j==2 & id==994
replace recode="440" if _j==2 & id==996
replace recode="120" if _j==2 & id==998
replace recode="730" if _j==2 & id==1005
replace recode="470" if _j==2 & id==1008
replace recode="440" if _j==2 & id==1009
replace recode="490" if _j==2 & id==1010
replace recode="410" if _j==2 & id==1018
replace recode="460" if _j==2 & id==1022
replace recode="219" if _j==2 & id==1032
replace recode="710" if _j==2 & id==1039
replace recode="440" if _j==2 & id==1041
replace recode="440" if _j==2 & id==1043
replace recode="219" if _j==2 & id==1047
replace recode="440" if _j==2 & id==1052
replace recode="410" if _j==2 & id==1067
replace recode="440" if _j==2 & id==1069
replace recode="440" if _j==2 & id==1070
replace recode="490" if _j==2 & id==1081
replace recode="236" if _j==2 & id==1082
replace recode="460" if _j==2 & id==1084
replace recode="450" if _j==2 & id==1093
replace recode="450" if _j==2 & id==1098
replace recode="450" if _j==2 & id==1103
replace recode="440" if _j==2 & id==1120
replace recode="440" if _j==2 & id==1121
replace recode="440" if _j==2 & id==1126
replace recode="440" if _j==2 & id==1136
replace recode="440" if _j==2 & id==1140
replace recode="440" if _j==2 & id==1148
replace recode="410" if _j==2 & id==1175
replace recode="430" if _j==2 & id==1188
replace recode="490" if _j==2 & id==1200
replace recode="130" if _j==2 & id==1225
replace recode="440" if _j==2 & id==1235
replace recode="530" if _j==2 & id==1236
replace recode="410" if _j==2 & id==1237
replace recode="480" if _j==2 & id==1241
replace recode="720" if _j==2 & id==1251
replace recode="440" if _j==2 & id==1261
replace recode="710" if _j==2 & id==1262
replace recode="450" if _j==2 & id==1265
replace recode="450" if _j==2 & id==1267
replace recode="450" if _j==2 & id==1268
replace recode="440" if _j==2 & id==1272
replace recode="440" if _j==2 & id==1274
replace recode="440" if _j==2 & id==1307

replace recode="491" if _j==3 & id==3
replace recode="440" if _j==3 & id==11
replace recode="229" if _j==3 & id==21
replace recode="480" if _j==3 & id==35
replace recode="440" if _j==3 & id==60
replace recode="440" if _j==3 & id==78
replace recode="110" if _j==3 & id==83
replace recode="440" if _j==3 & id==95
replace recode="450" if _j==3 & id==105
replace recode="340" if _j==3 & id==108
replace recode="219" if _j==3 & id==109
replace recode="110" if _j==3 & id==115
replace recode="440" if _j==3 & id==128
replace recode="720" if _j==3 & id==137
replace recode="440" if _j==3 & id==145
replace recode="480" if _j==3 & id==168
replace recode="450" if _j==3 & id==175
replace recode="480" if _j==3 & id==182
replace recode="440" if _j==3 & id==184
replace recode="490" if _j==3 & id==189
replace recode="480" if _j==3 & id==203
replace recode="440" if _j==3 & id==204
replace recode="220" if _j==3 & id==221
replace recode="440" if _j==3 & id==234
replace recode="440" if _j==3 & id==248
replace recode="480" if _j==3 & id==249
replace recode="235" if _j==3 & id==252
replace recode="229" if _j==3 & id==258
replace recode="480" if _j==3 & id==261
replace recode="220" if _j==3 & id==266
replace recode="480" if _j==3 & id==272
replace recode="440" if _j==3 & id==280
replace recode="480" if _j==3 & id==288
replace recode="490" if _j==3 & id==293
replace recode="480" if _j==3 & id==298
replace recode="480" if _j==3 & id==305
replace recode="410" if _j==3 & id==320
replace recode="450" if _j==3 & id==332
replace recode="234" if _j==3 & id==333
replace recode="110" if _j==3 & id==339
replace recode="590" if _j==3 & id==341
replace recode="480" if _j==3 & id==344
replace recode="720" if _j==3 & id==348
replace recode="130" if _j==3 & id==351
replace recode="440" if _j==3 & id==356
replace recode="130" if _j==3 & id==357
replace recode="490" if _j==3 & id==359
replace recode="440" if _j==3 & id==361
replace recode="440" if _j==3 & id==366
replace recode="130" if _j==3 & id==370
replace recode="480" if _j==3 & id==374
replace recode="130" if _j==3 & id==387
replace recode="110" if _j==3 & id==388
replace recode="490" if _j==3 & id==399
replace recode="490" if _j==3 & id==402
replace recode="130" if _j==3 & id==404
replace recode="440" if _j==3 & id==405
replace recode="130" if _j==3 & id==407
replace recode="130" if _j==3 & id==413
replace recode="490" if _j==3 & id==414
replace recode="130" if _j==3 & id==416
replace recode="410" if _j==3 & id==422
replace recode="110" if _j==3 & id==424
replace recode="720" if _j==3 & id==427
replace recode="440" if _j==3 & id==428
replace recode="130" if _j==3 & id==429
replace recode="120" if _j==3 & id==438
replace recode="420" if _j==3 & id==439
replace recode="590" if _j==3 & id==441
replace recode="590" if _j==3 & id==445
replace recode="590" if _j==3 & id==449
replace recode="130" if _j==3 & id==450
replace recode="440" if _j==3 & id==453
replace recode="130" if _j==3 & id==466
replace recode="490" if _j==3 & id==467
replace recode="410" if _j==3 & id==471
replace recode="212" if _j==3 & id==483
replace recode="410" if _j==3 & id==493
replace recode="220" if _j==3 & id==502
replace recode="340" if _j==3 & id==522
replace recode="590" if _j==3 & id==524
replace recode="440" if _j==3 & id==532
replace recode="120" if _j==3 & id==535
replace recode="720" if _j==3 & id==541
replace recode="450" if _j==3 & id==551
replace recode="460" if _j==3 & id==555
replace recode="210" if _j==3 & id==562
replace recode="410" if _j==3 & id==566
replace recode="440" if _j==3 & id==567
replace recode="229" if _j==3 & id==591
replace recode="440" if _j==3 & id==599
replace recode="490" if _j==3 & id==602
replace recode="440" if _j==3 & id==619
replace recode="440" if _j==3 & id==624
replace recode="480" if _j==3 & id==644
replace recode="410" if _j==3 & id==648
replace recode="730" if _j==3 & id==658
replace recode="410" if _j==3 & id==667
replace recode="450" if _j==3 & id==672
replace recode="410" if _j==3 & id==673
replace recode="440" if _j==3 & id==688
replace recode="440" if _j==3 & id==690
replace recode="340" if _j==3 & id==694
replace recode="450" if _j==3 & id==695
replace recode="410" if _j==3 & id==734
replace recode="120" if _j==3 & id==738
replace recode="440" if _j==3 & id==755
replace recode="460" if _j==3 & id==758
replace recode="440" if _j==3 & id==761
replace recode="110" if _j==3 & id==777
replace recode="410" if _j==3 & id==782
replace recode="440" if _j==3 & id==804
replace recode="440" if _j==3 & id==807
replace recode="440" if _j==3 & id==828
replace recode="410" if _j==3 & id==835
replace recode="410" if _j==3 & id==845
replace recode="240" if _j==3 & id==863
replace recode="440" if _j==3 & id==871
replace recode="720" if _j==3 & id==892
replace recode="720" if _j==3 & id==896
replace recode="110" if _j==3 & id==907
replace recode="410" if _j==3 & id==911
replace recode="720" if _j==3 & id==925
replace recode="440" if _j==3 & id==938
replace recode="130" if _j==3 & id==942
replace recode="440" if _j==3 & id==944
replace recode="440" if _j==3 & id==946
replace recode="440" if _j==3 & id==953
replace recode="480" if _j==3 & id==960
replace recode="440" if _j==3 & id==976
replace recode="490" if _j==3 & id==981
replace recode="440" if _j==3 & id==985
replace recode="212" if _j==3 & id==998
replace recode="490" if _j==3 & id==1004
replace recode="440" if _j==3 & id==1005
replace recode="490" if _j==3 & id==1006
replace recode="560" if _j==3 & id==1010
replace recode="440" if _j==3 & id==1016
replace recode="410" if _j==3 & id==1029
replace recode="440" if _j==3 & id==1041
replace recode="410" if _j==3 & id==1044
replace recode="440" if _j==3 & id==1055
replace recode="340" if _j==3 & id==1060
replace recode="440" if _j==3 & id==1070
replace recode="340" if _j==3 & id==1094
replace recode="720" if _j==3 & id==1114
replace recode="110" if _j==3 & id==1118
replace recode="440" if _j==3 & id==1120
replace recode="440" if _j==3 & id==1121
replace recode="420" if _j==3 & id==1124
replace recode="410" if _j==3 & id==1135
replace recode="590" if _j==3 & id==1146 // RIGHT OR LEFT HANDED???
replace recode="340" if _j==3 & id==1149
replace recode="440" if _j==3 & id==1156
replace recode="440" if _j==3 & id==1170
replace recode="440" if _j==3 & id==1177
replace recode="410" if _j==3 & id==1179
replace recode="490" if _j==3 & id==1183
replace recode="440" if _j==3 & id==1196
replace recode="440" if _j==3 & id==1200
replace recode="239" if _j==3 & id==1217
replace recode="530" if _j==3 & id==1223
replace recode="440" if _j==3 & id==1226
replace recode="480" if _j==3 & id==1229
replace recode="440" if _j==3 & id==1232
replace recode="440" if _j==3 & id==1233
replace recode="219" if _j==3 & id==1242
replace recode="440" if _j==3 & id==1247
replace recode="238" if _j==3 & id==1263
replace recode="238" if _j==3 & id==1267
replace recode="420" if _j==3 & id==1268
replace recode="720" if _j==3 & id==1276
replace recode="460" if _j==3 & id==1308
replace recode="340" if _j==3 & id==1313


* Agree on 0:
list id if levelagree==0

replace recode="730" if _j==1 & id==14
replace recode="720" if _j==1 & id==15
replace recode="720" if _j==1 & id==19
replace recode="240" if _j==1 & id==20
replace recode="491" if _j==1 & id==28
replace recode="440" if _j==1 & id==30
replace recode="450" if _j==1 & id==44
replace recode="233" if _j==1 & id==55
replace recode="590" if _j==1 & id==66
replace recode="240" if _j==1 & id==69
replace recode="430" if _j==1 & id==81
replace recode="560" if _j==1 & id==84
replace recode="340" if _j==1 & id==86
replace recode="237" if _j==1 & id==100
replace recode="237" if _j==1 & id==108
replace recode="730" if _j==1 & id==110
replace recode="560" if _j==1 & id==121
replace recode="120" if _j==1 & id==123
replace recode="218" if _j==1 & id==128
replace recode="460" if _j==1 & id==132
replace recode="590" if _j==1 & id==144
replace recode="730" if _j==1 & id==153
replace recode="710" if _j==1 & id==180
replace recode="227" if _j==1 & id==185
replace recode="234" if _j==1 & id==193
replace recode="710" if _j==1 & id==195
replace recode="730" if _j==1 & id==208
replace recode="490" if _j==1 & id==209
replace recode="720" if _j==1 & id==214
replace recode="730" if _j==1 & id==215
replace recode="240" if _j==1 & id==228
replace recode="410" if _j==1 & id==240
replace recode="440" if _j==1 & id==246
replace recode="110" if _j==1 & id==250
replace recode="219" if _j==1 & id==268
replace recode="227" if _j==1 & id==272
replace recode="720" if _j==1 & id==282
replace recode="120" if _j==1 & id==283
replace recode="240" if _j==1 & id==301
replace recode="234" if _j==1 & id==304
replace recode="240" if _j==1 & id==305
replace recode="240" if _j==1 & id==307
replace recode="228" if _j==1 & id==308
replace recode="560" if _j==1 & id==311
replace recode="318" if _j==1 & id==313
replace recode="450" if _j==1 & id==319
replace recode="450" if _j==1 & id==320
replace recode="720" if _j==1 & id==330
replace recode="410" if _j==1 & id==332
replace recode="324" if _j==1 & id==336
replace recode="720" if _j==1 & id==340
replace recode="410" if _j==1 & id==353
replace recode="410" if _j==1 & id==354
replace recode="450" if _j==1 & id==355
replace recode="720" if _j==1 & id==357
replace recode="410" if _j==1 & id==373
replace recode="120" if _j==1 & id==377
replace recode="410" if _j==1 & id==410
replace recode="410" if _j==1 & id==411
replace recode="410" if _j==1 & id==412
replace recode="410" if _j==1 & id==413
replace recode="410" if _j==1 & id==415
replace recode="730" if _j==1 & id==420
replace recode="410" if _j==1 & id==424
replace recode="480" if _j==1 & id==426
replace recode="410" if _j==1 & id==429
replace recode="410" if _j==1 & id==434
replace recode="340" if _j==1 & id==435
replace recode="227" if _j==1 & id==436
replace recode="226" if _j==1 & id==473
replace recode="560" if _j==1 & id==480
replace recode="110" if _j==1 & id==485
replace recode="730" if _j==1 & id==490
replace recode="710" if _j==1 & id==493
replace recode="730" if _j==1 & id==503
replace recode="730" if _j==1 & id==504
replace recode="340" if _j==1 & id==531
replace recode="410" if _j==1 & id==544
replace recode="410" if _j==1 & id==551
replace recode="720" if _j==1 & id==554
replace recode="410" if _j==1 & id==555
replace recode="120" if _j==1 & id==558
replace recode="220" if _j==1 & id==559
replace recode="440" if _j==1 & id==577
replace recode="410" if _j==1 & id==582
replace recode="720" if _j==1 & id==590
replace recode="410" if _j==1 & id==592
replace recode="710" if _j==1 & id==598
replace recode="710" if _j==1 & id==614
replace recode="220" if _j==1 & id==617
replace recode="730" if _j==1 & id==620
replace recode="710" if _j==1 & id==622
replace recode="410" if _j==1 & id==630
replace recode="410" if _j==1 & id==631
replace recode="340" if _j==1 & id==639
replace recode="230" if _j==1 & id==640
replace recode="240" if _j==1 & id==653
replace recode="590" if _j==1 & id==670
replace recode="560" if _j==1 & id==679
replace recode="240" if _j==1 & id==682
replace recode="450" if _j==1 & id==683
replace recode="120" if _j==1 & id==685
replace recode="410" if _j==1 & id==701
replace recode="410" if _j==1 & id==735
replace recode="730" if _j==1 & id==739
replace recode="710" if _j==1 & id==748
replace recode="710" if _j==1 & id==749
replace recode="410" if _j==1 & id==762
replace recode="240" if _j==1 & id==765
replace recode="480" if _j==1 & id==772
replace recode="240" if _j==1 & id==784
replace recode="240" if _j==1 & id==785
replace recode="730" if _j==1 & id==796
replace recode="480" if _j==1 & id==797
replace recode="560" if _j==1 & id==798
replace recode="480" if _j==1 & id==799
replace recode="710" if _j==1 & id==804
replace recode="220" if _j==1 & id==810
replace recode="730" if _j==1 & id==814
replace recode="460" if _j==1 & id==828
replace recode="410" if _j==1 & id==848
replace recode="710" if _j==1 & id==850
replace recode="340" if _j==1 & id==852
replace recode="710" if _j==1 & id==854
replace recode="220" if _j==1 & id==856
replace recode="340" if _j==1 & id==877
replace recode="238" if _j==1 & id==897
replace recode="231" if _j==1 & id==904
replace recode="720" if _j==1 & id==909
replace recode="720" if _j==1 & id==915
replace recode="710" if _j==1 & id==919
replace recode="240" if _j==1 & id==921
replace recode="240" if _j==1 & id==922
replace recode="340" if _j==1 & id==930
replace recode="450" if _j==1 & id==931
replace recode="120" if _j==1 & id==932
replace recode="490" if _j==1 & id==937
replace recode="240" if _j==1 & id==939
replace recode="410" if _j==1 & id==960
replace recode="240" if _j==1 & id==961
replace recode="240" if _j==1 & id==973
replace recode="720" if _j==1 & id==979
replace recode="120" if _j==1 & id==995
replace recode="710" if _j==1 & id==1003
replace recode="730" if _j==1 & id==1005
replace recode="220" if _j==1 & id==1026
replace recode="730" if _j==1 & id==1053
replace recode="730" if _j==1 & id==1054
replace recode="340" if _j==1 & id==1056
replace recode="710" if _j==1 & id==1064
replace recode="450" if _j==1 & id==1074
replace recode="219" if _j==1 & id==1080
replace recode="219" if _j==1 & id==1091
replace recode="120" if _j==1 & id==1092
replace recode="710" if _j==1 & id==1093
replace recode="120" if _j==1 & id==1094
replace recode="710" if _j==1 & id==1095
replace recode="219" if _j==1 & id==1104
replace recode="730" if _j==1 & id==1119
replace recode="440" if _j==1 & id==1125
replace recode="222" if _j==1 & id==1129
replace recode="590" if _j==1 & id==1156
replace recode="420" if _j==1 & id==1169
replace recode="120" if _j==1 & id==1176
replace recode="710" if _j==1 & id==1177
replace recode="340" if _j==1 & id==1179
replace recode="710" if _j==1 & id==1182
replace recode="710" if _j==1 & id==1183
replace recode="240" if _j==1 & id==1193
replace recode="340" if _j==1 & id==1195
replace recode="410" if _j==1 & id==1204
replace recode="120" if _j==1 & id==1208
replace recode="120" if _j==1 & id==1209
replace recode="130" if _j==1 & id==1214
replace recode="730" if _j==1 & id==1224
replace recode="340" if _j==1 & id==1226
replace recode="410" if _j==1 & id==1241
replace recode="710" if _j==1 & id==1244
replace recode="450" if _j==1 & id==1245
replace recode="110" if _j==1 & id==1253
replace recode="340" if _j==1 & id==1260
replace recode="450" if _j==1 & id==1267
replace recode="560" if _j==1 & id==1272
replace recode="720" if _j==1 & id==1280
replace recode="410" if _j==1 & id==1297
replace recode="120" if _j==1 & id==1310


replace recode="710" if _j==2 & id==19
replace recode="720" if _j==2 & id==26
replace recode="340" if _j==2 & id==30
replace recode="720" if _j==2 & id==51
replace recode="710" if _j==2 & id==69
replace recode="560" if _j==2 & id==106
replace recode="340" if _j==2 & id==108
replace recode="710" if _j==2 & id==112
replace recode="720" if _j==2 & id==122
replace recode="120" if _j==2 & id==123
replace recode="110" if _j==2 & id==130
replace recode="223" if _j==2 & id==147
replace recode="730" if _j==2 & id==156
replace recode="720" if _j==2 & id==160
replace recode="720" if _j==2 & id==169
replace recode="710" if _j==2 & id==170
replace recode="231" if _j==2 & id==184
replace recode="480" if _j==2 & id==188
replace recode="720" if _j==2 & id==192
replace recode="730" if _j==2 & id==195
replace recode="470" if _j==2 & id==197
replace recode="730" if _j==2 & id==201
replace recode="730" if _j==2 & id==204
replace recode="710" if _j==2 & id==205
replace recode="730" if _j==2 & id==206
replace recode="560" if _j==2 & id==209
replace recode="231" if _j==2 & id==212
replace recode="218" if _j==2 & id==223
replace recode="480" if _j==2 & id==232
replace recode="240" if _j==2 & id==243
replace recode="710" if _j==2 & id==248
replace recode="480" if _j==2 & id==249
replace recode="480" if _j==2 & id==269
replace recode="238" if _j==2 & id==271
replace recode="340" if _j==2 & id==275
replace recode="228" if _j==2 & id==276
replace recode="710" if _j==2 & id==283
replace recode="710" if _j==2 & id==293
replace recode="710" if _j==2 & id==294
replace recode="480" if _j==2 & id==301
replace recode="480" if _j==2 & id==310
replace recode="560" if _j==2 & id==311
replace recode="110" if _j==2 & id==312
replace recode="340" if _j==2 & id==318
replace recode="450" if _j==2 & id==320
replace recode="237" if _j==2 & id==321
replace recode="560" if _j==2 & id==325
replace recode="228" if _j==2 & id==330
replace recode="340" if _j==2 & id==333
replace recode="560" if _j==2 & id==336
replace recode="720" if _j==2 & id==343
replace recode="560" if _j==2 & id==352
replace recode="710" if _j==2 & id==357
replace recode="340" if _j==2 & id==360
replace recode="410" if _j==2 & id==373
replace recode="560" if _j==2 & id==388
replace recode="710" if _j==2 & id==389
replace recode="710" if _j==2 & id==391
replace recode="340" if _j==2 & id==406
replace recode="410" if _j==2 & id==410
replace recode="224" if _j==2 & id==412
replace recode="730" if _j==2 & id==420
replace recode="340" if _j==2 & id==421
replace recode="340" if _j==2 & id==424
replace recode="450" if _j==2 & id==436
replace recode="340" if _j==2 & id==453
replace recode="340" if _j==2 & id==467
replace recode="340" if _j==2 & id==470
replace recode="340" if _j==2 & id==475
replace recode="560" if _j==2 & id==478
replace recode="340" if _j==2 & id==484
replace recode="730" if _j==2 & id==491
replace recode="590" if _j==2 & id==492
replace recode="720" if _j==2 & id==493
replace recode="730" if _j==2 & id==502
replace recode="730" if _j==2 & id==503
replace recode="730" if _j==2 & id==504
replace recode="730" if _j==2 & id==512
replace recode="340" if _j==2 & id==519
replace recode="240" if _j==2 & id==523
replace recode="410" if _j==2 & id==526
replace recode="240" if _j==2 & id==532
replace recode="110" if _j==2 & id==548
replace recode="110" if _j==2 & id==551
replace recode="560" if _j==2 & id==557
replace recode="720" if _j==2 & id==561
replace recode="460" if _j==2 & id==564
replace recode="240" if _j==2 & id==565
replace recode="710" if _j==2 & id==571
replace recode="110" if _j==2 & id==572
replace recode="120" if _j==2 & id==574
replace recode="110" if _j==2 & id==594
replace recode="110" if _j==2 & id==612
replace recode="730" if _j==2 & id==620
replace recode="340" if _j==2 & id==622
replace recode="720" if _j==2 & id==623
replace recode="730" if _j==2 & id==626
replace recode="230" if _j==2 & id==631
replace recode="450" if _j==2 & id==638
replace recode="730" if _j==2 & id==650
replace recode="720" if _j==2 & id==657
replace recode="710" if _j==2 & id==668
replace recode="230" if _j==2 & id==670
replace recode="110" if _j==2 & id==674
replace recode="340" if _j==2 & id==681
replace recode="340" if _j==2 & id==685
replace recode="130" if _j==2 & id==694
replace recode="720" if _j==2 & id==702
replace recode="560" if _j==2 & id==716
replace recode="730" if _j==2 & id==718
replace recode="450" if _j==2 & id==720
replace recode="590" if _j==2 & id==739
replace recode="590" if _j==2 & id==747
replace recode="710" if _j==2 & id==765
replace recode="239" if _j==2 & id==768
replace recode="240" if _j==2 & id==772
replace recode="720" if _j==2 & id==792
replace recode="228" if _j==2 & id==801
replace recode="720" if _j==2 & id==810
replace recode="730" if _j==2 & id==814
replace recode="490" if _j==2 & id==821
replace recode="710" if _j==2 & id==835
replace recode="410" if _j==2 & id==844
replace recode="480" if _j==2 & id==859
replace recode="710" if _j==2 & id==879
replace recode="239" if _j==2 & id==897
replace recode="730" if _j==2 & id==898
replace recode="450" if _j==2 & id==899
replace recode="340" if _j==2 & id==903
replace recode="720" if _j==2 & id==909
replace recode="720" if _j==2 & id==915
replace recode="450" if _j==2 & id==916
replace recode="120" if _j==2 & id==919
replace recode="110" if _j==2 & id==928
replace recode="590" if _j==2 & id==929
replace recode="410" if _j==2 & id==939
replace recode="240" if _j==2 & id==962
replace recode="560" if _j==2 & id==963
replace recode="410" if _j==2 & id==965
replace recode="130" if _j==2 & id==966
replace recode="410" if _j==2 & id==970
replace recode="340" if _j==2 & id==973
replace recode="120" if _j==2 & id==993
replace recode="730" if _j==2 & id==1006
replace recode="340" if _j==2 & id==1011
replace recode="340" if _j==2 & id==1014
replace recode="710" if _j==2 & id==1021
replace recode="440" if _j==2 & id==1054
replace recode="420" if _j==2 & id==1056
replace recode="410" if _j==2 & id==1057
replace recode="450" if _j==2 & id==1060
replace recode="710" if _j==2 & id==1065
replace recode="710" if _j==2 & id==1076
replace recode="318" if _j==2 & id==1078
replace recode="450" if _j==2 & id==1079
replace recode="730" if _j==2 & id==1085
replace recode="340" if _j==2 & id==1086
replace recode="340" if _j==2 & id==1091
replace recode="340" if _j==2 & id==1107
replace recode="410" if _j==2 & id==1110
replace recode="231" if _j==2 & id==1129
replace recode="340" if _j==2 & id==1146
replace recode="340" if _j==2 & id==1149
replace recode="410" if _j==2 & id==1150
replace recode="410" if _j==2 & id==1151
replace recode="710" if _j==2 & id==1155
replace recode="110" if _j==2 & id==1166
replace recode="110" if _j==2 & id==1167
replace recode="420" if _j==2 & id==1172
replace recode="340" if _j==2 & id==1173
replace recode="240" if _j==2 & id==1178
replace recode="710" if _j==2 & id==1189
replace recode="240" if _j==2 & id==1195
replace recode="560" if _j==2 & id==1198
replace recode="240" if _j==2 & id==1210
replace recode="231" if _j==2 & id==1211
replace recode="720" if _j==2 & id==1220
replace recode="410" if _j==2 & id==1221
replace recode="410" if _j==2 & id==1222
replace recode="110" if _j==2 & id==1239
replace recode="211" if _j==2 & id==1258
replace recode="340" if _j==2 & id==1269
replace recode="710" if _j==2 & id==1276
replace recode="120" if _j==2 & id==1277
replace recode="520" if _j==2 & id==1295
replace recode="410" if _j==2 & id==1297
replace recode="110" if _j==2 & id==1299
replace recode="340" if _j==2 & id==1303
replace recode="240" if _j==2 & id==1308
replace recode="410" if _j==2 & id==1309
replace recode="410" if _j==2 & id==1314
replace recode="560" if _j==2 & id==1317


replace recode="540" if _j==3 & id==9
replace recode="590" if _j==3 & id==17
replace recode="590" if _j==3 & id==29
replace recode="450" if _j==3 & id==30
replace recode="120" if _j==3 & id==31
replace recode="340" if _j==3 & id==38
replace recode="120" if _j==3 & id==39
replace recode="340" if _j==3 & id==40
replace recode="217" if _j==3 & id==55
replace recode="340" if _j==3 & id==57
replace recode="560" if _j==3 & id==58
replace recode="560" if _j==3 & id==69
replace recode="450" if _j==3 & id==87
replace recode="710" if _j==3 & id==89
replace recode="560" if _j==3 & id==91
replace recode="228" if _j==3 & id==113
replace recode="120" if _j==3 & id==117
replace recode="720" if _j==3 & id==127
replace recode="560" if _j==3 & id==133
replace recode="233" if _j==3 & id==138
replace recode="410" if _j==3 & id==143
replace recode="490" if _j==3 & id==152
replace recode="730" if _j==3 & id==153
replace recode="730" if _j==3 & id==156
replace recode="730" if _j==3 & id==160
replace recode="730" if _j==3 & id==169
replace recode="560" if _j==3 & id==171
replace recode="560" if _j==3 & id==172
replace recode="240" if _j==3 & id==179
replace recode="480" if _j==3 & id==191
replace recode="450" if _j==3 & id==192
replace recode="720" if _j==3 & id==195
replace recode="560" if _j==3 & id==202
replace recode="730" if _j==3 & id==217
replace recode="240" if _j==3 & id==243
replace recode="490" if _j==3 & id==244
replace recode="440" if _j==3 & id==245
replace recode="450" if _j==3 & id==246
replace recode="490" if _j==3 & id==247
replace recode="440" if _j==3 & id==250
replace recode="120" if _j==3 & id==257
replace recode="720" if _j==3 & id==276
replace recode="560" if _j==3 & id==289
replace recode="730" if _j==3 & id==296
replace recode="560" if _j==3 & id==297
replace recode="240" if _j==3 & id==299
replace recode="110" if _j==3 & id==324
replace recode="560" if _j==3 & id==326
replace recode="340" if _j==3 & id==327
replace recode="560" if _j==3 & id==328
replace recode="720" if _j==3 & id==330
replace recode="410" if _j==3 & id==337
replace recode="730" if _j==3 & id==340
replace recode="560" if _j==3 & id==342
replace recode="340" if _j==3 & id==347
replace recode="560" if _j==3 & id==352
replace recode="340" if _j==3 & id==362
replace recode="560" if _j==3 & id==368
replace recode="730" if _j==3 & id==377
replace recode="560" if _j==3 & id==384
replace recode="560" if _j==3 & id==392
replace recode="450" if _j==3 & id==393
replace recode="440" if _j==3 & id==395
replace recode="110" if _j==3 & id==396
replace recode="110" if _j==3 & id==408
replace recode="730" if _j==3 & id==420
replace recode="590" if _j==3 & id==426
replace recode="560" if _j==3 & id==432
replace recode="120" if _j==3 & id==459
replace recode="730" if _j==3 & id==463
replace recode="730" if _j==3 & id==464
replace recode="240" if _j==3 & id==476
replace recode="590" if _j==3 & id==486
replace recode="240" if _j==3 & id==489
replace recode="480" if _j==3 & id==490
replace recode="710" if _j==3 & id==492
replace recode="730" if _j==3 & id==503
replace recode="730" if _j==3 & id==504
replace recode="450" if _j==3 & id==507
replace recode="220" if _j==3 & id==512
replace recode="560" if _j==3 & id==525
replace recode="240" if _j==3 & id==526
replace recode="120" if _j==3 & id==529
replace recode="340" if _j==3 & id==542
replace recode="410" if _j==3 & id==547
replace recode="460" if _j==3 & id==548
replace recode="320" if _j==3 & id==556
replace recode="720" if _j==3 & id==557
replace recode="237" if _j==3 & id==572
replace recode="240" if _j==3 & id==583
replace recode="240" if _j==3 & id==600
replace recode="110" if _j==3 & id==603
replace recode="480" if _j==3 & id==604
replace recode="224" if _j==3 & id==611
replace recode="710" if _j==3 & id==614
replace recode="340" if _j==3 & id==617
replace recode="320" if _j==3 & id==621
replace recode="720" if _j==3 & id==626
replace recode="720" if _j==3 & id==630
replace recode="340" if _j==3 & id==642
replace recode="340" if _j==3 & id==643
replace recode="730" if _j==3 & id==657
replace recode="450" if _j==3 & id==665
replace recode="420" if _j==3 & id==671
replace recode="560" if _j==3 & id==678
replace recode="710" if _j==3 & id==681
replace recode="490" if _j==3 & id==686
replace recode="710" if _j==3 & id==689
replace recode="450" if _j==3 & id==692
replace recode="720" if _j==3 & id==701
replace recode="720" if _j==3 & id==718
replace recode="730" if _j==3 & id==720
replace recode="420" if _j==3 & id==733
replace recode="231" if _j==3 & id==737
replace recode="231" if _j==3 & id==740
replace recode="590" if _j==3 & id==745
replace recode="720" if _j==3 & id==748
replace recode="730" if _j==3 & id==764
replace recode="234" if _j==3 & id==768
replace recode="420" if _j==3 & id==772
replace recode="490" if _j==3 & id==779
replace recode="240" if _j==3 & id==800
replace recode="730" if _j==3 & id==814
replace recode="560" if _j==3 & id==836
replace recode="450" if _j==3 & id==849
replace recode="420" if _j==3 & id==850
replace recode="480" if _j==3 & id==859
replace recode="340" if _j==3 & id==861
replace recode="430" if _j==3 & id==894
replace recode="120" if _j==3 & id==895
replace recode="238" if _j==3 & id==897
replace recode="730" if _j==3 & id==898
replace recode="237" if _j==3 & id==908
replace recode="410" if _j==3 & id==918
replace recode="240" if _j==3 & id==922
replace recode="110" if _j==3 & id==924
replace recode="590" if _j==3 & id==932
replace recode="340" if _j==3 & id==936
replace recode="450" if _j==3 & id==947
replace recode="440" if _j==3 & id==956
replace recode="730" if _j==3 & id==958
replace recode="410" if _j==3 & id==962
replace recode="220" if _j==3 & id==964
replace recode="238" if _j==3 & id==965
replace recode="510" if _j==3 & id==966
replace recode="224" if _j==3 & id==970
replace recode="490" if _j==3 & id==993
replace recode="590" if _j==3 & id==995
replace recode="120" if _j==3 & id==1007
replace recode="450" if _j==3 & id==1024
replace recode="120" if _j==3 & id==1031
replace recode="120" if _j==3 & id==1033
replace recode="710" if _j==3 & id==1046
replace recode="238" if _j==3 & id==1047
replace recode="440" if _j==3 & id==1054
replace recode="238" if _j==3 & id==1061
replace recode="710" if _j==3 & id==1065
replace recode="710" if _j==3 & id==1072
replace recode="710" if _j==3 & id==1073
replace recode="590" if _j==3 & id==1074
replace recode="590" if _j==3 & id==1081
replace recode="420" if _j==3 & id==1083
replace recode="450" if _j==3 & id==1085
replace recode="410" if _j==3 & id==1091
replace recode="560" if _j==3 & id==1097
replace recode="460" if _j==3 & id==1107
replace recode="110" if _j==3 & id==1113
replace recode="730" if _j==3 & id==1119
replace recode="730" if _j==3 & id==1129
replace recode="710" if _j==3 & id==1141
replace recode="340" if _j==3 & id==1147
replace recode="450" if _j==3 & id==1162
replace recode="130" if _j==3 & id==1168
replace recode="238" if _j==3 & id==1174
replace recode="340" if _j==3 & id==1176
replace recode="560" if _j==3 & id==1181
replace recode="420" if _j==3 & id==1182
replace recode="420" if _j==3 & id==1184
replace recode="560" if _j==3 & id==1188
replace recode="410" if _j==3 & id==1194
replace recode="130" if _j==3 & id==1203
replace recode="110" if _j==3 & id==1215
replace recode="340" if _j==3 & id==1218
replace recode="130" if _j==3 & id==1219
replace recode="560" if _j==3 & id==1220
replace recode="710" if _j==3 & id==1239
replace recode="490" if _j==3 & id==1252
replace recode="314" if _j==3 & id==1258
replace recode="237" if _j==3 & id==1261
replace recode="560" if _j==3 & id==1274
replace recode="120" if _j==3 & id==1277
replace recode="710" if _j==3 & id==1284
replace recode="223" if _j==3 & id==1289
replace recode="560" if _j==3 & id==1305
replace recode="720" if _j==3 & id==1306
replace recode="730" if _j==3 & id==1315
replace recode="110" if _j==3 & id==1316
replace recode="710" if _j==3 & id==1318

* A few missed!
list id _j if levelagree~=3 & recode==""

replace recode="224" if _j==1 & id==416
replace recode="490" if _j==1 & id==450
replace recode="324" if _j==1 & id==547
replace recode="450" if _j==1 & id==564
replace recode="480" if _j==1 & id==887
replace recode="217" if _j==1 & id==888
replace recode="340" if _j==1 & id==1256
replace recode="480" if _j==1 & id==1300
replace recode="120" if _j==1 & id==1316

replace recode="410" if _j==2 & id==20
replace recode="450" if _j==2 & id==94
replace recode="430" if _j==2 & id==239

replace recode="730" if _j==3 & id==206
replace recode="440" if _j==3 & id==220
replace recode="110" if _j==3 & id==254
replace recode="560" if _j==3 & id==887
replace recode="480" if _j==3 & id==905

save combined_codes_cleaned, replace


***** PART 2: CREATING MAIN DATASET *****
*****************************************

clear all
set more off
set matsize 4000 

*** Combine cleaned coding data with respondent information

use TMYK2_IGS, clear

drop psid pid finishedpct finished-mayor_3 comp_1-comp_3 clerk_1-clerk_3 judge_1-judge_3
rename response_id rresponse_id
save IGS_indiv_data, replace

*clear all
*use combined_codes_cleaned, clear
*merge m:1 rresponse_id using IGS_indiv_data, nogenerate

*drop if id==.

*save tmyk2_master, replace

*** Cleaning up data
use tmyk2_master, clear

rename recode info
replace info=rstring if info==""

g subcat=substr(info,1,1)
order subcat, a(info)

g office="Mayor" if mayor_infoneed~=.
replace office="Clerk" if clerk_infoneed~=.
replace office="Comptroller" if comp_infoneed~=.
replace office="Judge" if judge_infoneed~=.

egen infon=rowtotal(mayor_infoneed clerk_infoneed comp_infoneed judge_infoneed), missing
g infoneed=(infon-1)/4

g ok_1=1 if office=="Mayor" & mayor_know1==3
replace ok_1=1 if office=="Comptroller" & comp_know1==3
replace ok_1=1 if office=="Clerk" & clerk_know1==3
replace ok_1=1 if office=="Judge" & judge_know1==3
replace ok_1=0 if ok_1==.

g ok_2_holder=mayor_know2+comp_know2+clerk_know2+judge_know2

g ok_21=1 if strpos(ok_2_holder, "3") 
replace ok_21=0 if ok_21~=1 & office~=""
g ok_22=1 if strpos(ok_2_holder, "4") & office=="Mayor" 
replace ok_22=1 if strpos(ok_2_holder, "4") & office=="Judge"
replace ok_22=1 if strpos(ok_2_holder, "4")==0 & office=="Clerk"
replace ok_22=1 if strpos(ok_2_holder, "4")==0 & office=="Comptroller"
replace ok_22=0 if ok_22~=1 & office~=""
g ok_23=1 if strpos(ok_2_holder, "5") & office~="Judge"
replace ok_23=1 if strpos(ok_2_holder, "5")==0 & office=="Judge"
replace ok_23=0 if ok_23~=1 & office~=""
g ok_24=1 if strpos(ok_2_holder, "2") & office=="Comptroller"
replace ok_24=1 if strpos(ok_2_holder, "2") & office=="Clerk"
replace ok_24=1 if strpos(ok_2_holder, "2")==0 & office=="Judge"
replace ok_24=1 if strpos(ok_2_holder, "2")==0 & office=="Mayor"
replace ok_24=0 if ok_24~=1 & office~=""
g ok_25=0 if strpos(ok_2_holder, "1")
replace ok_25=1 if ok_25~=0 & office~=""

egen officeknowledge = rowtotal(ok_1 ok_21 ok_22 ok_23 ok_24 ok_25), missing
egen officeknowledge2 = rowtotal(ok_21 ok_22 ok_23 ok_24 ok_25), missing
g officeknowl=officeknowledge/6
g officeknowl2=officeknowledge2/5


rename gen gend

*Generating party and demographic variables
rename pid_b leand
rename pid_c leanr
rename pid_d leani

gen pid_7 = .
replace pid_7 = 1 if leand == 1
replace pid_7 = 2 if leand == 2
replace pid_7 = 3 if leani == 2
replace pid_7 = 4 if leani == 3
replace pid_7 = 5 if leani == 1
replace pid_7 = 6 if leanr == 2
replace pid_7 = 7 if leanr == 1

gen pid_3 = ""
replace pid_3 = "D" if inrange(pid_7,1,3)
replace pid_3 = "R" if inrange(pid_7,5,7)
replace pid_3 = "I" if pid_7 == 4

g extremity = abs(pid_7-4)

gen ethnicity = ""
replace ethnicity = "White" if race==1
replace ethnicity = "Black" if race==2
replace ethnicity = "Asian" if race==3
replace ethnicity = "Other" if race==4 | race==5 | race==6
replace ethnicity = "Latino" if race==8

g white=1 if ethnicity=="White"
replace white=0 if white~=1

gen gender = ""
replace gender = "Male" if gend == 1
replace gender = "Female" if gend == 2

encode gender, generate(sex)

gen education = edu
replace education = 5 if edu==6 | edu==7
label define education 1 "Less than HS" 2 "HS or equivalent" 3 "Some college" 4 "College" 5 "Some grad or graduate degree"
label val education education

replace age=. if age==9999987

gen age_st = .
replace age_st = 1 if inrange(age,18,24)
replace age_st = 2 if inrange(age,25,34)
replace age_st = 3 if inrange(age,35,44)
replace age_st = 4 if inrange(age,45,64)
replace age_st = 5 if inrange(age,65,99)
label define age_st 1 "18-24" 2 "25-34" 3 "35-44" 4 "45-64" 5 "65+"
label val age_st age_st

replace income=10 if income==9999987
lab def income 1 "Less than $20,000" ///
2	"$20,000-$29,999" ///
3	"$30,000-$39,999" ///
4	"$40,000-$49,999" ///
5	"$50,000-$59,999" ///
6	"$60,000-$74,999" ///
7	"$75,000-$99,999" ///
8	"$100,000-$149,999" ///
9	"$150,000+" ///
10	"Don't know/prefer not to state"
lab val income income 

label def rel ///
1	"Evangelical Protestant" ///
2	"Non-Evangelical Protestant" ///
3	"Catholic" ///
4	"Jewish" ///
5	"Muslim" ///
6	"Buddhist" ///
7	"Hindu" ///
8	"Atheist" ///
9	"Agnostic" ///
10	"Eastern Orthodox" ///
11	"Other" ///
12	"None" ///

label val religion rel

g newrel = religion
replace newrel=5 if religion > 5
replace newrel = 6 if religion==8 
replace newrel = 6 if religion==9
replace newrel = 6 if religion==12

lab def newrel ///
1	"Evangelical Protestant" ///
2	"Non-Evangelical Protestant" ///
3	"Catholic" ///
4	"Jewish" ///
5	"Other" ///
6	"None" 
lab val newrel newrel

g november="Hillary" if nov_vote==1
replace november="Trump" if nov_vote==2
replace november="Other" if nov_vote>2

encode november, generate(nov)

rename _j rank

g subsub=substr(info,1,2)

g offg = 1 if office=="Mayor"
replace offg=2 if office=="Comptroller"
replace offg=3 if office=="Clerk"
replace offg=4 if office=="Judge"
lab def offg 1 "Mayor" 2 "Comptroller" 3 "Clerk" 4 "Judge"

* By office knowledge and office
destring info, generate(inf)

tab subcat, generate(cat)
rename cat1 political
rename cat2 prospective
rename cat3 retrospective
rename cat4 mutable
rename cat5 immutable
rename cat6 goofing

* Creating alternative categories that treat profession as political/policy var
g retrospective2=1 if retrospective==1 | info=="410"
replace retrospective2=0 if retrospective2~=1

g mutable2=1 if mutable==1 & info~="410"
replace mutable2=0 if mutable2~=1

g subcat2=subcat
replace subcat2="3" if info=="410"

* Average
g rrank = rank
recode rrank 1=3 3=1 // Makes first-place worth 3, third-place worth 1

egen catrmean=mean(rrank), by(subcat)
g catmean=catrmean-2

egen catrmean2=mean(rrank), by(subcat2)
g catmean2=catrmean-2


saveold tmyk2_full_forsean, replace







************************************************
******* GENERATING DATASET FOR 3RD STUDY *******
************************************************


***** PART 1: CODING RESPONSES *****
************************************

set more off
set matsize 4000 


clear all
insheet using "tmyk3_jcodes.csv", comma
drop if id==.
rename * j= 
rename jid id
rename jresponse_id response_id
save julia, replace

clear all
insheet using "tmyk3_mcodes.csv", comma
rename * m= 
rename mid id
rename mresponse_id response_id
save marissa, replace

clear all
use julia, clear
merge 1:1 id using marissa, nogenerate // No issues with merge - all rows merged

reshape long jinfo minfo, i(id)
order minfo, after(jinfo)
gen fullagree= jinfo==minfo 

tostring jinfo minfo, replace

gen fullcatagree= substr(jinfo, 1, 2)==substr(minfo, 1, 2) 
replace fullcatagree=. if fullagree==1

gen catagree= substr(jinfo, 1, 1)==substr(minfo, 1, 1) 
replace catagree=. if fullagree==1 | fullcatagree==1

gen noagree= fullagree~=1 & fullcatagree~=1 & catagree~=1
replace noagree=. if fullagree==1 | fullcatagree==1 | catagree==1

gen levelagree=3 if fullagree==1
replace levelagree=2 if fullcatagree==1
replace levelagree=1 if catagree==1
replace levelagree=0 if noagree==1

order levelagree, after(minfo)

destring jinfo minfo, replace

gen recode=""
order recode, after(levelagree)

sort levelagree _j id

clonevar jstring = jinfo
clonevar mstring = minfo
tostring jstring mstring, replace

**** Generate code resolution

* Agree on 2
list id _j if levelagree==2

replace recode="233" if _j==1 & id==5
replace recode="233" if _j==1 & id==15
replace recode="229" if _j==1 & id==25
replace recode="229" if _j==1 & id==41
replace recode="213" if _j==1 & id==71
replace recode="228" if _j==1 & id==130
replace recode="540" if _j==1 & id==131
replace recode="422" if _j==1 & id==135
replace recode="229" if _j==1 & id==153
replace recode="219" if _j==1 & id==173
replace recode="219" if _j==1 & id==184
replace recode="214" if _j==1 & id==188
replace recode="234" if _j==1 & id==200
replace recode="218" if _j==1 & id==242
replace recode="229" if _j==1 & id==245
replace recode="219" if _j==1 & id==284
replace recode="212" if _j==1 & id==292
replace recode="228" if _j==1 & id==313
replace recode="219" if _j==1 & id==322
replace recode="219" if _j==1 & id==363
replace recode="219" if _j==1 & id==369
replace recode="219" if _j==1 & id==406
replace recode="422" if _j==1 & id==423
replace recode="110" if _j==1 & id==475
replace recode="227" if _j==1 & id==535
replace recode="220" if _j==1 & id==539
replace recode="320" if _j==1 & id==555
replace recode="224" if _j==1 & id==588
replace recode="224" if _j==1 & id==705
replace recode="224" if _j==1 & id==727
replace recode="229" if _j==1 & id==749
replace recode="239" if _j==1 & id==783
replace recode="238" if _j==1 & id==791
replace recode="560" if _j==1 & id==813
replace recode="227" if _j==1 & id==814
replace recode="229" if _j==1 & id==826
replace recode="219" if _j==1 & id==844
replace recode="219" if _j==1 & id==867
replace recode="219" if _j==1 & id==869
replace recode="227" if _j==1 & id==870
replace recode="229" if _j==1 & id==908
replace recode="229" if _j==1 & id==912
replace recode="219" if _j==1 & id==941
replace recode="224" if _j==1 & id==958
replace recode="229" if _j==1 & id==973
replace recode="219" if _j==1 & id==984
replace recode="237" if _j==1 & id==994
replace recode="213" if _j==1 & id==1011
replace recode="219" if _j==1 & id==1094
replace recode="229" if _j==1 & id==1105
replace recode="222" if _j==1 & id==1120
replace recode="220" if _j==1 & id==1138
replace recode="219" if _j==1 & id==1143
replace recode="219" if _j==1 & id==1214
replace recode="219" if _j==1 & id==1293
replace recode="420" if _j==1 & id==1308
replace recode="219" if _j==1 & id==1358
replace recode="217" if _j==1 & id==1399
replace recode="228" if _j==1 & id==1417
replace recode="222" if _j==1 & id==1472
replace recode="324" if _j==1 & id==1491
replace recode="219" if _j==1 & id==1530
replace recode="219" if _j==1 & id==1578
replace recode="229" if _j==1 & id==1590
replace recode="239" if _j==1 & id==1621
replace recode="219" if _j==1 & id==1634
replace recode="420" if _j==1 & id==1645
replace recode="212" if _j==1 & id==1697
replace recode="219" if _j==1 & id==1698
replace recode="490" if _j==1 & id==1751
replace recode="233" if _j==1 & id==1753
replace recode="231" if _j==2 & id==19
replace recode="222" if _j==2 & id==25
replace recode="229" if _j==2 & id==74
replace recode="218" if _j==2 & id==75
replace recode="220" if _j==2 & id==126
replace recode="231" if _j==2 & id==207
replace recode="230" if _j==2 & id==235
replace recode="219" if _j==2 & id==248
replace recode="229" if _j==2 & id==253
replace recode="212" if _j==2 & id==259
replace recode="229" if _j==2 & id==298
replace recode="233" if _j==2 & id==312
replace recode="212" if _j==2 & id==350
replace recode="231" if _j==2 & id==428
replace recode="224" if _j==2 & id==432
replace recode="430" if _j==2 & id==521
replace recode="219" if _j==2 & id==532
replace recode="220" if _j==2 & id==573
replace recode="229" if _j==2 & id==627
replace recode="219" if _j==2 & id==653
replace recode="217" if _j==2 & id==663
replace recode="237" if _j==2 & id==791
replace recode="219" if _j==2 & id==830
replace recode="220" if _j==2 & id==877
replace recode="219" if _j==2 & id==888
replace recode="229" if _j==2 & id==890
replace recode="228" if _j==2 & id==927
replace recode="217" if _j==2 & id==939
replace recode="219" if _j==2 & id==940
replace recode="214" if _j==2 & id==976
replace recode="220" if _j==2 & id==984
replace recode="226" if _j==2 & id==1015
replace recode="218" if _j==2 & id==1021
replace recode="217" if _j==2 & id==1032
replace recode="233" if _j==2 & id==1057
replace recode="229" if _j==2 & id==1090
replace recode="540" if _j==2 & id==1095
replace recode="219" if _j==2 & id==1104
replace recode="217" if _j==2 & id==1112
replace recode="233" if _j==2 & id==1126
replace recode="218" if _j==2 & id==1147
replace recode="220" if _j==2 & id==1179
replace recode="234" if _j==2 & id==1188
replace recode="224" if _j==2 & id==1190
replace recode="219" if _j==2 & id==1226
replace recode="560" if _j==2 & id==1242
replace recode="233" if _j==2 & id==1256
replace recode="219" if _j==2 & id==1280
replace recode="221" if _j==2 & id==1298
replace recode="219" if _j==2 & id==1338
replace recode="219" if _j==2 & id==1405
replace recode="491" if _j==2 & id==1425
replace recode="231" if _j==2 & id==1449
replace recode="219" if _j==2 & id==1455
replace recode="222" if _j==2 & id==1459
replace recode="228" if _j==2 & id==1493
replace recode="218" if _j==2 & id==1500
replace recode="213" if _j==2 & id==1510
replace recode="224" if _j==2 & id==1530
replace recode="540" if _j==2 & id==1542
replace recode="219" if _j==2 & id==1591
replace recode="219" if _j==2 & id==1685
replace recode="219" if _j==2 & id==1699
replace recode="227" if _j==2 & id==1707
replace recode="219" if _j==2 & id==1714
replace recode="220" if _j==2 & id==1744
replace recode="214" if _j==2 & id==1751
replace recode="212" if _j==3 & id==34
replace recode="229" if _j==3 & id==39
replace recode="219" if _j==3 & id==41
replace recode="239" if _j==3 & id==48
replace recode="239" if _j==3 & id==52
replace recode="236" if _j==3 & id==57
replace recode="228" if _j==3 & id==63
replace recode="231" if _j==3 & id==92
replace recode="239" if _j==3 & id==104
replace recode="231" if _j==3 & id==110
replace recode="227" if _j==3 & id==115
replace recode="540" if _j==3 & id==134
replace recode="110" if _j==3 & id==164
replace recode="221" if _j==3 & id==200
replace recode="219" if _j==3 & id==251
replace recode="216" if _j==3 & id==259
replace recode="220" if _j==3 & id==276
replace recode="219" if _j==3 & id==313
replace recode="219" if _j==3 & id==369
replace recode="220" if _j==3 & id==508
replace recode="239" if _j==3 & id==535
replace recode="227" if _j==3 & id==566
replace recode="218" if _j==3 & id==588
replace recode="219" if _j==3 & id==615
replace recode="218" if _j==3 & id==639
replace recode="239" if _j==3 & id==726
replace recode="219" if _j==3 & id==740
replace recode="222" if _j==3 & id==746
replace recode="211" if _j==3 & id==831
replace recode="229" if _j==3 & id==862
replace recode="231" if _j==3 & id==870
replace recode="239" if _j==3 & id==896
replace recode="223" if _j==3 & id==898
replace recode="219" if _j==3 & id==902
replace recode="231" if _j==3 & id==912
replace recode="229" if _j==3 & id==1013
replace recode="210" if _j==3 & id==1024
replace recode="219" if _j==3 & id==1032
replace recode="219" if _j==3 & id==1038
replace recode="219" if _j==3 & id==1059
replace recode="237" if _j==3 & id==1081
replace recode="219" if _j==3 & id==1085
replace recode="233" if _j==3 & id==1102
replace recode="219" if _j==3 & id==1142
replace recode="420" if _j==3 & id==1151
replace recode="219" if _j==3 & id==1199
replace recode="491" if _j==3 & id==1306
replace recode="422" if _j==3 & id==1334
replace recode="219" if _j==3 & id==1401
replace recode="228" if _j==3 & id==1407
replace recode="239" if _j==3 & id==1410
replace recode="219" if _j==3 & id==1476
replace recode="234" if _j==3 & id==1480
replace recode="219" if _j==3 & id==1485
replace recode="420" if _j==3 & id==1504
replace recode="219" if _j==3 & id==1516
replace recode="217" if _j==3 & id==1530
replace recode="220" if _j==3 & id==1554
replace recode="231" if _j==3 & id==1600
replace recode="229" if _j==3 & id==1616
replace recode="224" if _j==3 & id==1657
replace recode="211" if _j==3 & id==1666
replace recode="220" if _j==3 & id==1685
replace recode="231" if _j==3 & id==1698
replace recode="218" if _j==3 & id==1735


* Agree on 1
list id _j if levelagree==1

replace recode="480" if _j==1 & id==7
replace recode="219" if _j==1 & id==11
replace recode="219" if _j==1 & id==12
replace recode="217" if _j==1 & id==21
replace recode="480" if _j==1 & id==38
replace recode="480" if _j==1 & id==45
replace recode="480" if _j==1 & id==51
replace recode="218" if _j==1 & id==58
replace recode="450" if _j==1 & id==70
replace recode="410" if _j==1 & id==73
replace recode="219" if _j==1 & id==77
replace recode="410" if _j==1 & id==78
replace recode="410" if _j==1 & id==81
replace recode="730" if _j==1 & id==85
replace recode="410" if _j==1 & id==89
replace recode="450" if _j==1 & id==96
replace recode="240" if _j==1 & id==99
replace recode="110" if _j==1 & id==106
replace recode="450" if _j==1 & id==116
replace recode="480" if _j==1 & id==124
replace recode="240" if _j==1 & id==147
replace recode="240" if _j==1 & id==148
replace recode="450" if _j==1 & id==181
replace recode="440" if _j==1 & id==185
replace recode="227" if _j==1 & id==189
replace recode="218" if _j==1 & id==193
replace recode="221" if _j==1 & id==194
replace recode="231" if _j==1 & id==204
replace recode="220" if _j==1 & id==219
replace recode="224" if _j==1 & id==246
replace recode="110" if _j==1 & id==272
replace recode="410" if _j==1 & id==299
replace recode="450" if _j==1 & id==301
replace recode="410" if _j==1 & id==309
replace recode="218" if _j==1 & id==312
replace recode="450" if _j==1 & id==349
replace recode="450" if _j==1 & id==364
replace recode="470" if _j==1 & id==379
replace recode="240" if _j==1 & id==411
replace recode="218" if _j==1 & id==414
replace recode="480" if _j==1 & id==433
replace recode="228" if _j==1 & id==440
replace recode="237" if _j==1 & id==445
replace recode="450" if _j==1 & id==451
replace recode="480" if _j==1 & id==461
replace recode="440" if _j==1 & id==513
replace recode="410" if _j==1 & id==515
replace recode="218" if _j==1 & id==520
replace recode="239" if _j==1 & id==532
replace recode="130" if _j==1 & id==534
replace recode="430" if _j==1 & id==543
replace recode="218" if _j==1 & id==549
replace recode="450" if _j==1 & id==575
replace recode="218" if _j==1 & id==589
replace recode="410" if _j==1 & id==601
replace recode="480" if _j==1 & id==617
replace recode="410" if _j==1 & id==643
replace recode="240" if _j==1 & id==645
replace recode="450" if _j==1 & id==686
replace recode="237" if _j==1 & id==730
replace recode="440" if _j==1 & id==743
replace recode="110" if _j==1 & id==746
replace recode="224" if _j==1 & id==768
replace recode="450" if _j==1 & id==795
replace recode="491" if _j==1 & id==827
replace recode="240" if _j==1 & id==838
replace recode="491" if _j==1 & id==839
replace recode="234" if _j==1 & id==860
replace recode="410" if _j==1 & id==864
replace recode="491" if _j==1 & id==865
replace recode="450" if _j==1 & id==883
replace recode="420" if _j==1 & id==885
replace recode="218" if _j==1 & id==900
replace recode="110" if _j==1 & id==913
replace recode="222" if _j==1 & id==914
replace recode="450" if _j==1 & id==927
replace recode="410" if _j==1 & id==938
replace recode="218" if _j==1 & id==966
replace recode="120" if _j==1 & id==999
replace recode="410" if _j==1 & id==1002
replace recode="221" if _j==1 & id==1010
replace recode="239" if _j==1 & id==1048
replace recode="410" if _j==1 & id==1050
replace recode="240" if _j==1 & id==1051
replace recode="229" if _j==1 & id==1057
replace recode="229" if _j==1 & id==1107
replace recode="110" if _j==1 & id==1114
replace recode="224" if _j==1 & id==1175
replace recode="227" if _j==1 & id==1176
replace recode="227" if _j==1 & id==1188
replace recode="218" if _j==1 & id==1189
replace recode="227" if _j==1 & id==1227
replace recode="410" if _j==1 & id==1234
replace recode="450" if _j==1 & id==1241
replace recode="224" if _j==1 & id==1256
replace recode="410" if _j==1 & id==1257
replace recode="410" if _j==1 & id==1259
replace recode="240" if _j==1 & id==1264
replace recode="410" if _j==1 & id==1275
replace recode="240" if _j==1 & id==1276
replace recode="410" if _j==1 & id==1279
replace recode="213" if _j==1 & id==1287
replace recode="228" if _j==1 & id==1304
replace recode="410" if _j==1 & id==1314
replace recode="238" if _j==1 & id==1335
replace recode="730" if _j==1 & id==1346
replace recode="450" if _j==1 & id==1383
replace recode="228" if _j==1 & id==1385
replace recode="240" if _j==1 & id==1390
replace recode="221" if _j==1 & id==1392
replace recode="130" if _j==1 & id==1403
replace recode="110" if _j==1 & id==1448
replace recode="410" if _j==1 & id==1463
replace recode="219" if _j==1 & id==1485
replace recode="227" if _j==1 & id==1510
replace recode="491" if _j==1 & id==1534
replace recode="730" if _j==1 & id==1600
replace recode="227" if _j==1 & id==1651
replace recode="410" if _j==1 & id==1681
replace recode="218" if _j==1 & id==1696
replace recode="560" if _j==1 & id==1725
replace recode="218" if _j==1 & id==1738
replace recode="410" if _j==1 & id==1742
replace recode="240" if _j==2 & id==7
replace recode="410" if _j==2 & id==9
replace recode="227" if _j==2 & id==10
replace recode="410" if _j==2 & id==17
replace recode="219" if _j==2 & id==29
replace recode="491" if _j==2 & id==30
replace recode="240" if _j==2 & id==69
replace recode="240" if _j==2 & id==73
replace recode="239" if _j==2 & id==86
replace recode="240" if _j==2 & id==94
replace recode="222" if _j==2 & id==129
replace recode="720" if _j==2 & id==172
replace recode="450" if _j==2 & id==179
replace recode="240" if _j==2 & id==196
replace recode="110" if _j==2 & id==197
replace recode="227" if _j==2 & id==228
replace recode="227" if _j==2 & id==242
replace recode="440" if _j==2 & id==291
replace recode="240" if _j==2 & id==292
replace recode="440" if _j==2 & id==301
replace recode="450" if _j==2 & id==313
replace recode="410" if _j==2 & id==319
replace recode="120" if _j==2 & id==336
replace recode="218" if _j==2 & id==355
replace recode="430" if _j==2 & id==357
replace recode="410" if _j==2 & id==362
replace recode="218" if _j==2 & id==366
replace recode="450" if _j==2 & id==368
replace recode="440" if _j==2 & id==385
replace recode="239" if _j==2 & id==391
replace recode="120" if _j==2 & id==411
replace recode="480" if _j==2 & id==434
replace recode="480" if _j==2 & id==437
replace recode="440" if _j==2 & id==450
replace recode="220" if _j==2 & id==453
replace recode="227" if _j==2 & id==459
replace recode="229" if _j==2 & id==460
replace recode="240" if _j==2 & id==467
replace recode="239" if _j==2 & id==490
replace recode="340" if _j==2 & id==491
replace recode="440" if _j==2 & id==513
replace recode="450" if _j==2 & id==526
replace recode="410" if _j==2 & id==540
replace recode="214" if _j==2 & id==542
replace recode="410" if _j==2 & id==550
replace recode="560" if _j==2 & id==556
replace recode="218" if _j==2 & id==566
replace recode="231" if _j==2 & id==570
replace recode="218" if _j==2 & id==595
replace recode="440" if _j==2 & id==641
replace recode="450" if _j==2 & id==652
replace recode="240" if _j==2 & id==655
replace recode="238" if _j==2 & id==662
replace recode="218" if _j==2 & id==665
replace recode="218" if _j==2 & id==689
replace recode="410" if _j==2 & id==695
replace recode="130" if _j==2 & id==701
replace recode="450" if _j==2 & id==725
replace recode="224" if _j==2 & id==744
replace recode="239" if _j==2 & id==783
replace recode="225" if _j==2 & id==808
replace recode="218" if _j==2 & id==811
replace recode="440" if _j==2 & id==815
replace recode="218" if _j==2 & id==819
replace recode="211" if _j==2 & id==820
replace recode="240" if _j==2 & id==821
replace recode="228" if _j==2 & id==831
replace recode="228" if _j==2 & id==836
replace recode="110" if _j==2 & id==883
replace recode="218" if _j==2 & id==896
replace recode="218" if _j==2 & id==900
replace recode="410" if _j==2 & id==931
replace recode="218" if _j==2 & id==945
replace recode="219" if _j==2 & id==947
replace recode="430" if _j==2 & id==959
replace recode="238" if _j==2 & id==977
replace recode="218" if _j==2 & id==982
replace recode="440" if _j==2 & id==995
replace recode="491" if _j==2 & id==1004
replace recode="410" if _j==2 & id==1042
replace recode="237" if _j==2 & id==1045
replace recode="410" if _j==2 & id==1060
replace recode="480" if _j==2 & id==1064
replace recode="234" if _j==2 & id==1077
replace recode="229" if _j==2 & id==1102
replace recode="110" if _j==2 & id==1160
replace recode="440" if _j==2 & id==1200
replace recode="218" if _j==2 & id==1214
replace recode="234" if _j==2 & id==1227
replace recode="450" if _j==2 & id==1229
replace recode="450" if _j==2 & id==1268
replace recode="420" if _j==2 & id==1270
replace recode="229" if _j==2 & id==1277
replace recode="450" if _j==2 & id==1284
replace recode="239" if _j==2 & id==1287
replace recode="220" if _j==2 & id==1299
replace recode="730" if _j==2 & id==1346
replace recode="420" if _j==2 & id==1349
replace recode="440" if _j==2 & id==1374
replace recode="240" if _j==2 & id==1377
replace recode="450" if _j==2 & id==1381
replace recode="234" if _j==2 & id==1382
replace recode="234" if _j==2 & id==1399
replace recode="212" if _j==2 & id==1400
replace recode="410" if _j==2 & id==1408
replace recode="491" if _j==2 & id==1424
replace recode="410" if _j==2 & id==1434
replace recode="440" if _j==2 & id==1471
replace recode="237" if _j==2 & id==1511
replace recode="218" if _j==2 & id==1526
replace recode="240" if _j==2 & id==1541
replace recode="450" if _j==2 & id==1544
replace recode="110" if _j==2 & id==1587
replace recode="450" if _j==2 & id==1594
replace recode="450" if _j==2 & id==1597
replace recode="730" if _j==2 & id==1600
replace recode="730" if _j==2 & id==1603
replace recode="410" if _j==2 & id==1631
replace recode="240" if _j==2 & id==1640
replace recode="110" if _j==2 & id==1646
replace recode="440" if _j==2 & id==1688
replace recode="450" if _j==2 & id==1702
replace recode="410" if _j==2 & id==1705
replace recode="430" if _j==2 & id==1713
replace recode="110" if _j==2 & id==1737
replace recode="240" if _j==3 & id==16
replace recode="227" if _j==3 & id==25
replace recode="218" if _j==3 & id==27
replace recode="450" if _j==3 & id==30
replace recode="480" if _j==3 & id==35
replace recode="480" if _j==3 & id==46
replace recode="240" if _j==3 & id==73
replace recode="218" if _j==3 & id==75
replace recode="240" if _j==3 & id==77
replace recode="240" if _j==3 & id==81
replace recode="240" if _j==3 & id==82
replace recode="218" if _j==3 & id==86
replace recode="364" if _j==3 & id==94
replace recode="240" if _j==3 & id==96
replace recode="240" if _j==3 & id==98
replace recode="110" if _j==3 & id==119
replace recode="239" if _j==3 & id==122
replace recode="440" if _j==3 & id==143
replace recode="450" if _j==3 & id==152
replace recode="450" if _j==3 & id==153
replace recode="450" if _j==3 & id==170
replace recode="110" if _j==3 & id==186
replace recode="460" if _j==3 & id==191
replace recode="410" if _j==3 & id==196
replace recode="490" if _j==3 & id==199
replace recode="440" if _j==3 & id==205
replace recode="218" if _j==3 & id==214
replace recode="218" if _j==3 & id==219
replace recode="440" if _j==3 & id==239
replace recode="430" if _j==3 & id==248
replace recode="480" if _j==3 & id==295
replace recode="450" if _j==3 & id==301
replace recode="238" if _j==3 & id==315
replace recode="120" if _j==3 & id==325
replace recode="240" if _j==3 & id==332
replace recode="239" if _j==3 & id==334
replace recode="450" if _j==3 & id==349
replace recode="227" if _j==3 & id==351
replace recode="120" if _j==3 & id==364
replace recode="210" if _j==3 & id==373
replace recode="440" if _j==3 & id==390
replace recode="480" if _j==3 & id==392
replace recode="450" if _j==3 & id==403
replace recode="440" if _j==3 & id==426
replace recode="229" if _j==3 & id==435
replace recode="450" if _j==3 & id==451
replace recode="239" if _j==3 & id==462
replace recode="480" if _j==3 & id==469
replace recode="480" if _j==3 & id==477
replace recode="410" if _j==3 & id==493
replace recode="490" if _j==3 & id==498
replace recode="410" if _j==3 & id==513
replace recode="420" if _j==3 & id==526
replace recode="490" if _j==3 & id==537
replace recode="440" if _j==3 & id==541
replace recode="450" if _j==3 & id==560
replace recode="450" if _j==3 & id==561
replace recode="730" if _j==3 & id==581
replace recode="239" if _j==3 & id==590
replace recode="234" if _j==3 & id==596
replace recode="227" if _j==3 & id==597
replace recode="450" if _j==3 & id==616
replace recode="410" if _j==3 & id==617
replace recode="410" if _j==3 & id==628
replace recode="238" if _j==3 & id==632
replace recode="239" if _j==3 & id==638
replace recode="218" if _j==3 & id==652
replace recode="237" if _j==3 & id==656
replace recode="440" if _j==3 & id==672
replace recode="450" if _j==3 & id==681
replace recode="450" if _j==3 & id==683
replace recode="440" if _j==3 & id==693
replace recode="240" if _j==3 & id==702
replace recode="212" if _j==3 & id==735
replace recode="120" if _j==3 & id==738
replace recode="450" if _j==3 & id==741
replace recode="210" if _j==3 & id==755
replace recode="490" if _j==3 & id==765
replace recode="240" if _j==3 & id==772
replace recode="450" if _j==3 & id==779
replace recode="410" if _j==3 & id==781
replace recode="420" if _j==3 & id==794
replace recode="410" if _j==3 & id==810
replace recode="440" if _j==3 & id==829
replace recode="227" if _j==3 & id==873
replace recode="120" if _j==3 & id==887
replace recode="110" if _j==3 & id==894
replace recode="218" if _j==3 & id==900
replace recode="440" if _j==3 & id==904
replace recode="218" if _j==3 & id==925
replace recode="110" if _j==3 & id==928
replace recode="229" if _j==3 & id==939
replace recode="237" if _j==3 & id==943
replace recode="213" if _j==3 & id==947
replace recode="240" if _j==3 & id==953
replace recode="410" if _j==3 & id==956
replace recode="110" if _j==3 & id==962
replace recode="238" if _j==3 & id==993
replace recode="440" if _j==3 & id==995
replace recode="410" if _j==3 & id==996
replace recode="720" if _j==3 & id==1001
replace recode="440" if _j==3 & id==1006
replace recode="238" if _j==3 & id==1009
replace recode="410" if _j==3 & id==1028
replace recode="120" if _j==3 & id==1041
replace recode="430" if _j==3 & id==1042
replace recode="228" if _j==3 & id==1046
replace recode="239" if _j==3 & id==1048
replace recode="450" if _j==3 & id==1051
replace recode="110" if _j==3 & id==1072
replace recode="720" if _j==3 & id==1073
replace recode="720" if _j==3 & id==1111
replace recode="450" if _j==3 & id==1118
replace recode="450" if _j==3 & id==1130
replace recode="237" if _j==3 & id==1149
replace recode="218" if _j==3 & id==1150
replace recode="480" if _j==3 & id==1163
replace recode="110" if _j==3 & id==1182
replace recode="120" if _j==3 & id==1202
replace recode="720" if _j==3 & id==1211
replace recode="440" if _j==3 & id==1216
replace recode="229" if _j==3 & id==1227
replace recode="120" if _j==3 & id==1233
replace recode="229" if _j==3 & id==1238
replace recode="440" if _j==3 & id==1250
replace recode="410" if _j==3 & id==1302
replace recode="218" if _j==3 & id==1309
replace recode="480" if _j==3 & id==1312
replace recode="240" if _j==3 & id==1324
replace recode="120" if _j==3 & id==1326
replace recode="240" if _j==3 & id==1337
replace recode="410" if _j==3 & id==1340
replace recode="410" if _j==3 & id==1349
replace recode="410" if _j==3 & id==1352
replace recode="450" if _j==3 & id==1368
replace recode="237" if _j==3 & id==1422
replace recode="227" if _j==3 & id==1426
replace recode="120" if _j==3 & id==1429
replace recode="218" if _j==3 & id==1434
replace recode="440" if _j==3 & id==1436
replace recode="440" if _j==3 & id==1470
replace recode="410" if _j==3 & id==1473
replace recode="480" if _j==3 & id==1478
replace recode="221" if _j==3 & id==1499
replace recode="430" if _j==3 & id==1507
replace recode="450" if _j==3 & id==1515
replace recode="410" if _j==3 & id==1534
replace recode="240" if _j==3 & id==1535
replace recode="440" if _j==3 & id==1551
replace recode="210" if _j==3 & id==1557
replace recode="450" if _j==3 & id==1580
replace recode="218" if _j==3 & id==1591
replace recode="228" if _j==3 & id==1592
replace recode="480" if _j==3 & id==1596
replace recode="730" if _j==3 & id==1603
replace recode="210" if _j==3 & id==1612
replace recode="219" if _j==3 & id==1624
replace recode="440" if _j==3 & id==1626
replace recode="240" if _j==3 & id==1627
replace recode="239" if _j==3 & id==1628
replace recode="240" if _j==3 & id==1645
replace recode="239" if _j==3 & id==1654
replace recode="440" if _j==3 & id==1660
replace recode="218" if _j==3 & id==1661
replace recode="120" if _j==3 & id==1665
replace recode="130" if _j==3 & id==1668
replace recode="218" if _j==3 & id==1674
replace recode="228" if _j==3 & id==1696
replace recode="218" if _j==3 & id==1701
replace recode="450" if _j==3 & id==1703
replace recode="450" if _j==3 & id==1709

replace recode="120" if _j==1 & id==325
replace recode="450" if _j==3 & id==1702


* Agree on 0
list id _j jstring mstring if levelagree==0

replace recode="480" if _j==1 & id==22
replace recode="491" if _j==1 & id==23
replace recode="220" if _j==1 & id==24
replace recode="320" if _j==1 & id==32
replace recode="240" if _j==1 & id==40
replace recode="240" if _j==1 & id==55
replace recode="491" if _j==1 & id==57
replace recode="480" if _j==1 & id==59
replace recode="480" if _j==1 & id==68
replace recode="340" if _j==1 & id==69
replace recode="120" if _j==1 & id==91
replace recode="490" if _j==1 & id==97
replace recode="120" if _j==1 & id==100
replace recode="491" if _j==1 & id==102
replace recode="322" if _j==1 & id==118
replace recode="340" if _j==1 & id==128
replace recode="410" if _j==1 & id==133
replace recode="320" if _j==1 & id==139
replace recode="560" if _j==1 & id==145
replace recode="540" if _j==1 & id==154
replace recode="340" if _j==1 & id==155
replace recode="340" if _j==1 & id==159
replace recode="217" if _j==1 & id==162
replace recode="110" if _j==1 & id==164
replace recode="240" if _j==1 & id==166
replace recode="410" if _j==1 & id==167
replace recode="240" if _j==1 & id==170
replace recode="450" if _j==1 & id==175
replace recode="480" if _j==1 & id==176
replace recode="110" if _j==1 & id==190
replace recode="340" if _j==1 & id==191
replace recode="560" if _j==1 & id==196
replace recode="240" if _j==1 & id==206
replace recode="240" if _j==1 & id==210
replace recode="440" if _j==1 & id==211
replace recode="480" if _j==1 & id==216
replace recode="480" if _j==1 & id==220
replace recode="480" if _j==1 & id==221
replace recode="480" if _j==1 & id==223
replace recode="480" if _j==1 & id==225


* Stopped to identify patterns
replace recode="480" if levelagree<=1 & substr(jstring,1,3)=="340" & substr(mstring,1,3)=="480"
replace recode="240" if levelagree<=1 & substr(jstring,1,3)=="240" & substr(mstring,1,3)=="110"


* Restarting
list id _j jstring mstring if levelagree==0 & recode==""

replace recode="240" if _j==1 & id==240
replace recode="530" if _j==1 & id==266
replace recode="218" if _j==1 & id==267
replace recode="491" if _j==1 & id==291
replace recode="221" if _j==1 & id==293
replace recode="410" if _j==1 & id==308
replace recode="460" if _j==1 & id==316
replace recode="210" if _j==1 & id==346
replace recode="440" if _j==1 & id==352
replace recode="110" if _j==1 & id==370
replace recode="228" if _j==1 & id==380
replace recode="530" if _j==1 & id==387
replace recode="450" if _j==1 & id==400
replace recode="410" if _j==1 & id==436
replace recode="340" if _j==1 & id==437
replace recode="560" if _j==1 & id==458
replace recode="480" if _j==1 & id==465
replace recode="410" if _j==1 & id==467
replace recode="237" if _j==1 & id==468
replace recode="480" if _j==1 & id==476
replace recode="240" if _j==1 & id==495
replace recode="560" if _j==1 & id==500
replace recode="110" if _j==1 & id==501
replace recode="410" if _j==1 & id==509
replace recode="320" if _j==1 & id==516
replace recode="410" if _j==1 & id==526
replace recode="410" if _j==1 & id==533
replace recode="410" if _j==1 & id==537
replace recode="410" if _j==1 & id==580
replace recode="560" if _j==1 & id==583
replace recode="110" if _j==1 & id==598
replace recode="240" if _j==1 & id==609
replace recode="224" if _j==1 & id==653
replace recode="240" if _j==1 & id==657
replace recode="340" if _j==1 & id==671
replace recode="120" if _j==1 & id==681
replace recode="410" if _j==1 & id==704
replace recode="110" if _j==1 & id==708
replace recode="130" if _j==1 & id==739
replace recode="410" if _j==1 & id==753
replace recode="730" if _j==1 & id==760
replace recode="240" if _j==1 & id==764
replace recode="221" if _j==1 & id==769
replace recode="730" if _j==1 & id==775
replace recode="410" if _j==1 & id==776
replace recode="440" if _j==1 & id==789
replace recode="130" if _j==1 & id==799
replace recode="730" if _j==1 & id==829
replace recode="730" if _j==1 & id==833
replace recode="240" if _j==1 & id==835
replace recode="130" if _j==1 & id==836
replace recode="480" if _j==1 & id==840
replace recode="480" if _j==1 & id==857
replace recode="240" if _j==1 & id==859
replace recode="480" if _j==1 & id==868
replace recode="240" if _j==1 & id==887
replace recode="219" if _j==1 & id==890
replace recode="110" if _j==1 & id==924
replace recode="110" if _j==1 & id==928
replace recode="440" if _j==1 & id==936
replace recode="480" if _j==1 & id==943
replace recode="440" if _j==1 & id==944
replace recode="240" if _j==1 & id==946
replace recode="220" if _j==1 & id==1001
replace recode="110" if _j==1 & id==1034
replace recode="240" if _j==1 & id==1045
replace recode="324" if _j==1 & id==1058
replace recode="410" if _j==1 & id==1061
replace recode="130" if _j==1 & id==1072
replace recode="480" if _j==1 & id==1091
replace recode="240" if _j==1 & id==1095
replace recode="240" if _j==1 & id==1103
replace recode="480" if _j==1 & id==1111
replace recode="240" if _j==1 & id==1116
replace recode="240" if _j==1 & id==1128
replace recode="410" if _j==1 & id==1132
replace recode="410" if _j==1 & id==1136
replace recode="340" if _j==1 & id==1137
replace recode="340" if _j==1 & id==1146
replace recode="240" if _j==1 & id==1162
replace recode="450" if _j==1 & id==1163
replace recode="410" if _j==1 & id==1166
replace recode="237" if _j==1 & id==1174
replace recode="560" if _j==1 & id==1184
replace recode="240" if _j==1 & id==1185
replace recode="730" if _j==1 & id==1193
replace recode="730" if _j==1 & id==1195
replace recode="130" if _j==1 & id==1202
replace recode="240" if _j==1 & id==1206
replace recode="340" if _j==1 & id==1216
replace recode="240" if _j==1 & id==1220
replace recode="480" if _j==1 & id==1254
replace recode="480" if _j==1 & id==1270
replace recode="314" if _j==1 & id==1272
replace recode="480" if _j==1 & id==1273
replace recode="130" if _j==1 & id==1274
replace recode="218" if _j==1 & id==1277
replace recode="227" if _j==1 & id==1278
replace recode="228" if _j==1 & id==1285
replace recode="240" if _j==1 & id==1298
replace recode="130" if _j==1 & id==1309
replace recode="430" if _j==1 & id==1310
replace recode="110" if _j==1 & id==1328
replace recode="450" if _j==1 & id==1333
replace recode="228" if _j==1 & id==1342
replace recode="480" if _j==1 & id==1345
replace recode="240" if _j==1 & id==1349
replace recode="222" if _j==1 & id==1350
replace recode="320" if _j==1 & id==1366
replace recode="730" if _j==1 & id==1374
replace recode="110" if _j==1 & id==1393
replace recode="730" if _j==1 & id==1398
replace recode="560" if _j==1 & id==1416
replace recode="450" if _j==1 & id==1421
replace recode="110" if _j==1 & id==1434
replace recode="219" if _j==1 & id==1451
replace recode="480" if _j==1 & id==1466
replace recode="480" if _j==1 & id==1469
replace recode="240" if _j==1 & id==1492
replace recode="120" if _j==1 & id==1495
replace recode="410" if _j==1 & id==1515
replace recode="730" if _j==1 & id==1517
replace recode="322" if _j==1 & id==1526
replace recode="480" if _j==1 & id==1532
replace recode="240" if _j==1 & id==1533
replace recode="240" if _j==1 & id==1543
replace recode="730" if _j==1 & id==1547
replace recode="240" if _j==1 & id==1565
replace recode="410" if _j==1 & id==1592
replace recode="450" if _j==1 & id==1594
replace recode="430" if _j==1 & id==1609
replace recode="720" if _j==1 & id==1612
replace recode="110" if _j==1 & id==1618
replace recode="540" if _j==1 & id==1625
replace recode="110" if _j==1 & id==1631
replace recode="730" if _j==1 & id==1635
replace recode="240" if _j==1 & id==1637
replace recode="210" if _j==1 & id==1650
replace recode="110" if _j==1 & id==1660
replace recode="450" if _j==1 & id==1668
replace recode="320" if _j==1 & id==1682
replace recode="440" if _j==1 & id==1752
replace recode="410" if _j==2 & id==3
replace recode="410" if _j==2 & id==14
replace recode="130" if _j==2 & id==21
replace recode="221" if _j==2 & id==26
replace recode="110" if _j==2 & id==80
replace recode="214" if _j==2 & id==84
replace recode="240" if _j==2 & id==88
replace recode="440" if _j==2 & id==100
replace recode="410" if _j==2 & id==109
replace recode="340" if _j==2 & id==118
replace recode="220" if _j==2 & id==132
replace recode="491" if _j==2 & id==136
replace recode="120" if _j==2 & id==137
replace recode="410" if _j==2 & id==143
replace recode="491" if _j==2 & id==145
replace recode="340" if _j==2 & id==146
replace recode="450" if _j==2 & id==150
replace recode="490" if _j==2 & id==154
replace recode="460" if _j==2 & id==159
replace recode="210" if _j==2 & id==160
replace recode="220" if _j==2 & id==161
replace recode="450" if _j==2 & id==167
replace recode="490" if _j==2 & id==169
replace recode="211" if _j==2 & id==182
replace recode="240" if _j==2 & id==204
replace recode="240" if _j==2 & id==210
replace recode="440" if _j==2 & id==211
replace recode="491" if _j==2 & id==226
replace recode="410" if _j==2 & id==229
replace recode="340" if _j==2 & id==230
replace recode="218" if _j==2 & id==233
replace recode="329" if _j==2 & id==234
replace recode="212" if _j==2 & id==237
replace recode="110" if _j==2 & id==246
replace recode="340" if _j==2 & id==252
replace recode="480" if _j==2 & id==254
replace recode="240" if _j==2 & id==263
replace recode="240" if _j==2 & id==267
replace recode="221" if _j==2 & id==277
replace recode="480" if _j==2 & id==278
replace recode="491" if _j==2 & id==316
replace recode="240" if _j==2 & id==325
replace recode="340" if _j==2 & id==327
replace recode="410" if _j==2 & id==329
replace recode="220" if _j==2 & id==333
replace recode="220" if _j==2 & id==338
replace recode="430" if _j==2 & id==352
replace recode="217" if _j==2 & id==365
replace recode="430" if _j==2 & id==372
replace recode="560" if _j==2 & id==382
replace recode="450" if _j==2 & id==403
replace recode="491" if _j==2 & id==418
replace recode="480" if _j==2 & id==433
replace recode="440" if _j==2 & id==444
replace recode="240" if _j==2 & id==461
replace recode="410" if _j==2 & id==487
replace recode="240" if _j==2 & id==546
replace recode="430" if _j==2 & id==567
replace recode="480" if _j==2 & id==568
replace recode="240" if _j==2 & id==569
replace recode="720" if _j==2 & id==581
replace recode="229" if _j==2 & id==583
replace recode="110" if _j==2 & id==598
replace recode="219" if _j==2 & id==607
replace recode="210" if _j==2 & id==610
replace recode="110" if _j==2 & id==613
replace recode="240" if _j==2 & id==614
replace recode="560" if _j==2 & id==617
replace recode="219" if _j==2 & id==621
replace recode="480" if _j==1 & id==894
replace recode="218" if _j==1 & id==1213
replace recode="240" if _j==1 & id==1339
replace recode="240" if _j==1 & id==1535
replace recode="560" if _j==2 & id==629
replace recode="560" if _j==2 & id==670
replace recode="490" if _j==2 & id==671
replace recode="410" if _j==2 & id==672
replace recode="560" if _j==2 & id==676
replace recode="240" if _j==2 & id==678
replace recode="440" if _j==2 & id==691
replace recode="240" if _j==2 & id==700
replace recode="410" if _j==2 & id==712
replace recode="110" if _j==2 & id==723
replace recode="491" if _j==2 & id==736
replace recode="340" if _j==2 & id==741
replace recode="340" if _j==2 & id==770
replace recode="240" if _j==2 & id==773
replace recode="730" if _j==2 & id==775
replace recode="560" if _j==2 & id==777
replace recode="430" if _j==2 & id==778
replace recode="720" if _j==2 & id==813
replace recode="480" if _j==2 & id==822
replace recode="480" if _j==2 & id==825
replace recode="240" if _j==2 & id==829
replace recode="120" if _j==2 & id==860
replace recode="220" if _j==2 & id==862
replace recode="720" if _j==2 & id==864
replace recode="237" if _j==2 & id==867
replace recode="430" if _j==2 & id==875
replace recode="410" if _j==2 & id==876
replace recode="410" if _j==2 & id==887
replace recode="340" if _j==2 & id==906
replace recode="238" if _j==2 & id==908
replace recode="450" if _j==2 & id==918
replace recode="210" if _j==2 & id==935
replace recode="217" if _j==2 & id==937
replace recode="340" if _j==2 & id==944
replace recode="560" if _j==2 & id==946
replace recode="590" if _j==2 & id==964
replace recode="460" if _j==2 & id==972
replace recode="430" if _j==2 & id==979
replace recode="490" if _j==2 & id==981
replace recode="240" if _j==2 & id==991
replace recode="237" if _j==2 & id==994
replace recode="240" if _j==2 & id==1008
replace recode="440" if _j==2 & id==1010
replace recode="410" if _j==2 & id==1025
replace recode="220" if _j==2 & id==1030
replace recode="410" if _j==2 & id==1039
replace recode="460" if _j==2 & id==1056
replace recode="240" if _j==2 & id==1072
replace recode="220" if _j==2 & id==1074
replace recode="120" if _j==2 & id==1075
replace recode="340" if _j==2 & id==1091
replace recode="560" if _j==2 & id==1093
replace recode="590" if _j==2 & id==1096
replace recode="410" if _j==2 & id==1108
replace recode="450" if _j==2 & id==1109
replace recode="410" if _j==2 & id==1116
replace recode="240" if _j==2 & id==1117
replace recode="560" if _j==2 & id==1136
replace recode="491" if _j==2 & id==1149
replace recode="220" if _j==2 & id==1163
replace recode="239" if _j==2 & id==1176
replace recode="480" if _j==2 & id==1182
replace recode="730" if _j==2 & id==1195
replace recode="240" if _j==2 & id==1204
replace recode="410" if _j==2 & id==1211
replace recode="560" if _j==2 & id==1217
replace recode="130" if _j==2 & id==1221
replace recode="110" if _j==2 & id==1230
replace recode="480" if _j==2 & id==1231
replace recode="226" if _j==2 & id==1238
replace recode="219" if _j==2 & id==1245
replace recode="480" if _j==2 & id==1253
replace recode="240" if _j==2 & id==1258
replace recode="560" if _j==2 & id==1263
replace recode="220" if _j==2 & id==1269
replace recode="217" if _j==2 & id==1273
replace recode="410" if _j==2 & id==1281
replace recode="410" if _j==2 & id==1291
replace recode="560" if _j==2 & id==1295
replace recode="560" if _j==2 & id==1300
replace recode="430" if _j==2 & id==1301
replace recode="460" if _j==2 & id==1309
replace recode="450" if _j==2 & id==1321
replace recode="212" if _j==2 & id==1325
replace recode="324" if _j==2 & id==1331
replace recode="730" if _j==2 & id==1350
replace recode="491" if _j==2 & id==1357
replace recode="410" if _j==2 & id==1369
replace recode="130" if _j==2 & id==1378
replace recode="450" if _j==2 & id==1387
replace recode="229" if _j==2 & id==1392
replace recode="220" if _j==2 & id==1393
replace recode="720" if _j==2 & id==1396
replace recode="720" if _j==2 & id==1398
replace recode="120" if _j==2 & id==1406
replace recode="229" if _j==2 & id==1407
replace recode="240" if _j==2 & id==1433
replace recode="410" if _j==2 & id==1452
replace recode="480" if _j==2 & id==1460
replace recode="440" if _j==2 & id==1462
replace recode="430" if _j==2 & id==1479
replace recode="340" if _j==2 & id==1483
replace recode="221" if _j==2 & id==1492
replace recode="240" if _j==2 & id==1494
replace recode="240" if _j==2 & id==1498
replace recode="410" if _j==2 & id==1499
replace recode="560" if _j==2 & id==1507
replace recode="730" if _j==2 & id==1517
replace recode="220" if _j==2 & id==1520
replace recode="220" if _j==2 & id==1565
replace recode="430" if _j==2 & id==1601
replace recode="430" if _j==2 & id==1612
replace recode="410" if _j==2 & id==1618
replace recode="130" if _j==2 & id==1619
replace recode="110" if _j==2 & id==1621
replace recode="450" if _j==2 & id==1626
replace recode="240" if _j==2 & id==1627
replace recode="219" if _j==2 & id==1644
replace recode="110" if _j==2 & id==1660
replace recode="110" if _j==2 & id==1710
replace recode="240" if _j==2 & id==1732
replace recode="460" if _j==2 & id==1733
replace recode="240" if _j==2 & id==1748
replace recode="730" if _j==3 & id==4
replace recode="237" if _j==3 & id==10
replace recode="340" if _j==3 & id==20
replace recode="120" if _j==3 & id==43
replace recode="420" if _j==3 & id==51
replace recode="340" if _j==3 & id==53
replace recode="130" if _j==3 & id==71
replace recode="217" if _j==3 & id==74
replace recode="237" if _j==3 & id==78
replace recode="217" if _j==3 & id==79
replace recode="237" if _j==3 & id==87
replace recode="450" if _j==3 & id==89
replace recode="450" if _j==3 & id==95
replace recode="720" if _j==3 & id==99
replace recode="730" if _j==3 & id==100
replace recode="450" if _j==3 & id==109
replace recode="110" if _j==3 & id==120
replace recode="540" if _j==3 & id==133
replace recode="450" if _j==3 & id==136
replace recode="340" if _j==3 & id==138
replace recode="720" if _j==3 & id==154
replace recode="120" if _j==3 & id==156
replace recode="410" if _j==3 & id==158
replace recode="212" if _j==3 & id==166
replace recode="221" if _j==3 & id==182
replace recode="221" if _j==3 & id==189
replace recode="229" if _j==3 & id==195
replace recode="217" if _j==3 & id==198
replace recode="450" if _j==3 & id==204
replace recode="490" if _j==3 & id==206
replace recode="340" if _j==3 & id==208
replace recode="440" if _j==3 & id==211
replace recode="491" if _j==3 & id==220
replace recode="120" if _j==3 & id==224
replace recode="730" if _j==3 & id==225
replace recode="520" if _j==3 & id==233
replace recode="333" if _j==3 & id==234
replace recode="410" if _j==3 & id==252
replace recode="237" if _j==3 & id==270
replace recode="224" if _j==3 & id==314
replace recode="560" if _j==3 & id==329
replace recode="238" if _j==3 & id==338
replace recode="730" if _j==3 & id==341
replace recode="450" if _j==3 & id==352
replace recode="320" if _j==3 & id==372
replace recode="120" if _j==3 & id==378
replace recode="240" if _j==3 & id==380
replace recode="410" if _j==3 & id==386
replace recode="229" if _j==3 & id==389
replace recode="450" if _j==3 & id==421
replace recode="560" if _j==3 & id==427
replace recode="110" if _j==3 & id==428
replace recode="229" if _j==3 & id==437
replace recode="238" if _j==3 & id==445
replace recode="560" if _j==3 & id==479
replace recode="410" if _j==3 & id==483
replace recode="229" if _j==3 & id==500
replace recode="410" if _j==3 & id==511
replace recode="229" if _j==3 & id==530
replace recode="450" if _j==3 & id==545
replace recode="340" if _j==3 & id==554
replace recode="219" if _j==3 & id==575
replace recode="430" if _j==3 & id==576
replace recode="340" if _j==3 & id==578
replace recode="410" if _j==3 & id==582
replace recode="730" if _j==3 & id==586
replace recode="450" if _j==3 & id==594
replace recode="560" if _j==3 & id==614
replace recode="560" if _j==3 & id==620
replace recode="240" if _j==3 & id==623
replace recode="130" if _j==3 & id==640
replace recode="120" if _j==3 & id==649
replace recode="120" if _j==3 & id==668
replace recode="210" if _j==3 & id==673
replace recode="240" if _j==3 & id==676
replace recode="590" if _j==3 & id==685
replace recode="410" if _j==3 & id==686
replace recode="560" if _j==3 & id==710
replace recode="239" if _j==3 & id==713
replace recode="560" if _j==3 & id==722
replace recode="217" if _j==3 & id==724
replace recode="430" if _j==3 & id==737
replace recode="590" if _j==3 & id==743
replace recode="410" if _j==3 & id==747
replace recode="730" if _j==3 & id==775
replace recode="240" if _j==3 & id==786
replace recode="240" if _j==3 & id==789
replace recode="440" if _j==3 & id==793
replace recode="440" if _j==3 & id==808
replace recode="240" if _j==3 & id==822
replace recode="233" if _j==3 & id==827
replace recode="219" if _j==3 & id==834
replace recode="410" if _j==3 & id==839
replace recode="490" if _j==3 & id==841
replace recode="480" if _j==3 & id==866
replace recode="340" if _j==3 & id==868
replace recode="110" if _j==3 & id==875
replace recode="240" if _j==3 & id==876
replace recode="239" if _j==3 & id==877
replace recode="220" if _j==3 & id==888
replace recode="410" if _j==3 & id==895
replace recode="340" if _j==3 & id==901
replace recode="430" if _j==3 & id==920
replace recode="450" if _j==3 & id==924
replace recode="590" if _j==3 & id==935
replace recode="238" if _j==3 & id==945
replace recode="240" if _j==3 & id==954
replace recode="480" if _j==3 & id==960
replace recode="238" if _j==3 & id==965
replace recode="440" if _j==3 & id==966
replace recode="421" if _j==3 & id==970
replace recode="228" if _j==3 & id==972
replace recode="218" if _j==3 & id==983
replace recode="229" if _j==3 & id==987
replace recode="240" if _j==3 & id==988
replace recode="410" if _j==3 & id==990
replace recode="240" if _j==3 & id==991
replace recode="410" if _j==3 & id==1017
replace recode="130" if _j==3 & id==1026
replace recode="237" if _j==3 & id==1027
replace recode="560" if _j==3 & id==1049
replace recode="491" if _j==3 & id==1054
replace recode="340" if _j==3 & id==1058
replace recode="120" if _j==3 & id==1062
replace recode="560" if _j==3 & id==1064
replace recode="240" if _j==3 & id==1066
replace recode="240" if _j==3 & id==1084
replace recode="110" if _j==3 & id==1095
replace recode="340" if _j==3 & id==1100
replace recode="240" if _j==3 & id==1104
replace recode="720" if _j==3 & id==1105
replace recode="219" if _j==3 & id==1106
replace recode="450" if _j==3 & id==1116
replace recode="430" if _j==3 & id==1123
replace recode="560" if _j==3 & id==1125
replace recode="340" if _j==3 & id==1133
replace recode="560" if _j==3 & id==1146
replace recode="328" if _j==3 & id==1152
replace recode="430" if _j==3 & id==1156
replace recode="430" if _j==3 & id==1158
replace recode="460" if _j==3 & id==1164
replace recode="130" if _j==3 & id==1177
replace recode="560" if _j==3 & id==1183
replace recode="730" if _j==3 & id==1195
replace recode="130" if _j==3 & id==1197
replace recode="238" if _j==3 & id==1205
replace recode="410" if _j==3 & id==1222
replace recode="217" if _j==3 & id==1223
replace recode="120" if _j==3 & id==1224
replace recode="240" if _j==3 & id==1229
replace recode="410" if _j==3 & id==1232
replace recode="480" if _j==3 & id==1241
replace recode="240" if _j==3 & id==1247
replace recode="410" if _j==3 & id==1252
replace recode="340" if _j==3 & id==1253
replace recode="421" if _j==3 & id==1254
replace recode="430" if _j==3 & id==1257
replace recode="120" if _j==3 & id==1260
replace recode="450" if _j==3 & id==1269
replace recode="440" if _j==3 & id==1273
replace recode="430" if _j==3 & id==1275
replace recode="240" if _j==3 & id==1276
replace recode="238" if _j==3 & id==1290
replace recode="560" if _j==3 & id==1295
replace recode="217" if _j==3 & id==1298
replace recode="110" if _j==3 & id==1308
replace recode="450" if _j==3 & id==1321
replace recode="340" if _j==3 & id==1325
replace recode="130" if _j==3 & id==1333
replace recode="224" if _j==3 & id==1335
replace recode="237" if _j==3 & id==1342
replace recode="730" if _j==3 & id==1350
replace recode="224" if _j==3 & id==1353
replace recode="220" if _j==3 & id==1362
replace recode="560" if _j==3 & id==1363
replace recode="560" if _j==3 & id==1375
replace recode="217" if _j==3 & id==1379
replace recode="239" if _j==3 & id==1382
replace recode="240" if _j==3 & id==1412
replace recode="440" if _j==3 & id==1420
replace recode="130" if _j==3 & id==1428
replace recode="219" if _j==3 & id==1445
replace recode="238" if _j==3 & id==1457
replace recode="450" if _j==3 & id==1460
replace recode="490" if _j==3 & id==1463
replace recode="237" if _j==3 & id==1465
replace recode="240" if _j==3 & id==1466
replace recode="120" if _j==3 & id==1468
replace recode="340" if _j==3 & id==1481
replace recode="120" if _j==3 & id==1482
replace recode="130" if _j==3 & id==1496
replace recode="560" if _j==3 & id==1508
replace recode="217" if _j==3 & id==1509
replace recode="480" if _j==3 & id==1511
replace recode="110" if _j==3 & id==1513
replace recode="730" if _j==3 & id==1517
replace recode="120" if _j==3 & id==1521
replace recode="237" if _j==3 & id==1526
replace recode="720" if _j==3 & id==1532
replace recode="410" if _j==3 & id==1536
replace recode="590" if _j==3 & id==1544
replace recode="450" if _j==3 & id==1550
replace recode="560" if _j==3 & id==1553
replace recode="590" if _j==3 & id==1566
replace recode="491" if _j==3 & id==1587
replace recode="110" if _j==3 & id==1590
replace recode="730" if _j==3 & id==1597
replace recode="340" if _j==3 & id==1611
replace recode="220" if _j==3 & id==1614
replace recode="110" if _j==3 & id==1615
replace recode="239" if _j==3 & id==1646
replace recode="560" if _j==3 & id==1652
replace recode="217" if _j==3 & id==1663
replace recode="590" if _j==3 & id==1669
replace recode="450" if _j==3 & id==1672
replace recode="730" if _j==3 & id==1695
replace recode="340" if _j==3 & id==1697
replace recode="480" if _j==3 & id==1720
replace recode="450" if _j==3 & id==1730
replace recode="480" if _j==3 & id==1742
replace recode="120" if _j==3 & id==1749
replace recode="219" if _j==3 & id==1168

save tmyk3_recoded, replace


***** PART 2: CREATING MAIN DATASET *****
*****************************************

*** converting to dta ***

insheet using "tmyk3_raw.csv", names clear
save tmyk3_raw, replace

insheet using "tmyk3pilot_raw.csv", names clear
save tmyk3pilot_raw, replace

*** cleaning tmyk3 raw ***

use tmyk3_raw, clear
drop if _n==1|_n==2

g mayortype=1 if q222!=""
replace mayortype=2 if q344!=""
replace mayortype=3 if q353!=""
replace mayortype=4 if q362!=""

g info1=q222 if mayortype==1
replace info1=q344 if mayortype==2
replace info1=q353 if mayortype==3
replace info1=q362 if mayortype==4
g info2=q224 if mayortype==1
replace info2=q346 if mayortype==2
replace info2=q355 if mayortype==3
replace info2=q364 if mayortype==4
g info3=q226 if mayortype==1
replace info3=q348 if mayortype==2
replace info3=q357 if mayortype==3
replace info3=q366 if mayortype==4

g mayor_pleased=q174 if mayortype==1
replace mayor_pleased=q350 if mayortype==2
replace mayor_pleased=q359 if mayortype==3
replace mayor_pleased=q368 if mayortype==4

g mayor_discouraged=q227 if mayortype==1
replace mayor_discouraged=q349 if mayortype==2
replace mayor_discouraged=q358 if mayortype==3
replace mayor_discouraged=q367 if mayortype==4

g corruption_scandal=1 if q204!=""|q386!=""|q390!=""|q394!=""|q430!=""|q434!=""|q438!=""|q442!=""|q767!=""|q771!=""|q775!=""|q779!=""
replace corruption_scandal=2 if q398!=""|q402!=""|q406!=""|q410!=""|q458!=""|q454!=""|q450!=""|q446!=""|q763!=""|q783!=""|q787!=""|q791!=""
replace corruption_scandal=3 if q414!=""|q418!=""|q422!=""|q426!=""|q474!=""|q470!=""|q466!=""|q462!=""|q795!=""|q799!=""|q803!=""|q807!=""

g corruption_type=1 if q204!=""|q398!=""|q414!=""|q462!=""|q430!=""|q446!=""|q779!=""|q763!=""|q795!=""
replace corruption_type=2 if q386!=""|q402!=""|q418!=""|q466!=""|q450!=""|q434!=""|q775!=""|q783!=""|q799!=""
replace corruption_type=3 if q390!=""|q406!=""|q422!=""|q470!=""|q454!=""|q438!=""|q771!=""|q787!=""|q803!=""
replace corruption_type=4 if q394!=""|q410!=""|q426!=""|q474!=""|q458!=""|q442!=""|q767!=""|q791!=""|q807!=""

g corruption_party=1 if q204!=""|q386!=""|q390!=""|q394!=""|q398!=""|q402!=""|q406!=""|q410!=""|q414!=""|q418!=""|q422!=""|q426!=""
replace corruption_party=2 if q430!=""|q434!=""|q438!=""|q442!=""|q458!=""|q454!=""|q450!=""|q446!=""|q474!=""|q470!=""|q466!=""|q462!=""
replace corruption_party=3 if q767!=""|q771!=""|q775!=""|q779!=""|q763!=""|q783!=""|q787!=""|q791!=""|q795!=""|q799!=""|q803!=""|q807!=""

g corruption_vote=q204 if q204!=""
for any q386 q390 q394 q430 q434 q438 q442 q767 q771 q775 q779 q398 q402 q406 q410 q458 q454 q450 q446 q763 q783 q787 q791 q414 q418 q422 q426 q474 q470 q466 q462 q795 q799 q803 q807: replace corruption_vote=X if X!=""

g corruption_feel=q205 if q204!=""
for any q387 q391 q395 q431 q435 q439 q443 q768 q772 q776 q780 q399 q403 q407 q411 q459 q455 q451 q447 q764 q784 q788 q792 q415 q419 q423 q427 q475 q471 q467 q463 q796 q800 q804 q808: replace corruption_feel=X if X!=""

g corruption_burden=q206 if q204!=""
for any q388 q392 q396 q432 q436 q440 q444 q769 q773 q777 q781 q400 q404 q408 q412 q460 q456 q452 q448 q765 q785 q789 q793 q416 q420 q424 q428 q476 q472 q468 q464 q797 q801 q805 q809: replace corruption_burden=X if X!=""

keep ipaddress durationinseconds finished responseid locationlatitude locationlongitude q49 q50 q51 q52 q53 q89 q90 q91 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17 a18 a19 a20 a21 a22 a23 a24 a25 a26 a27 a28 a29 a30 a31 a32 a33 a34 a35 a36 a37 a38 a39 a40 a41 a42 a43 a44 a45 a46 a47 a48 a49 a50  f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 f13 f14 f15 f16 f17 f18 f19 f20 f21 f22 f23 f24 f25 f26 f27 f28 f29 f30 f31 f32 f33 f34 f35 f36 f37 f38 f39 f40 f41 f42 f43 f44 f45 f46 f47 f48 f49 f50 m1 m2 m3 m4 m5 m6 m7 m8 m9 m10 m11 m12 m13 m14 m15 m16 m17 m18 m19 m20 m21 m22 m23 m24 m25 m26 m27 m28 m29 m30 m31 m32 m33 m34 m35 m36 m37 m38 m39 m40 m41 m42 m43 m44 m45 m46 m47 m48 m49 m50 d1 d2 d3 d4 d5 d6 d7 d8 d9 d10 d11 d12 d13 d14 d15 d16 d17 d18 d19 d20 d21 d22 d23 d24 d25 d26 d27 d28 d29 d30 d31 d32 d33 d34 d35 d36 d37 d38 d39 d40 d41 d42 d43 d44 d45 d46 d47 d48 d49 d50 g1 g2 g3 g4 g5 g6 g7 g8 g9 g10 g11 g12 g13 g14 g15 g16 g17 g18 g19 g20 g21 g22 g23 g24 g25 g26 g27 g28 g29 g30 g31 g32 g33 g34 g35 g36 g37 g38 g39 g40 g41 g42 g43 g44 g45 g46 g47 g48 g49 g50 attr1 attr2 attr3 attr4 attr5 attr6 attr7 attr8 attr9 attr10 attr11 attr12 attr13 attr14 attr15 attr16 attr17 attr18 attr19 attr20 attr21 attr22 attr23 attr24 attr25 attr26 attr27 attr28 attr29 attr30 attr31 attr32 attr33 attr34 attr35 attr36 attr37 attr38 attr39 attr40 attr41 attr42 attr43 attr44 attr45 attr46 attr47 attr48 attr49 attr50 dom1 dom2 dom3 dom4 dom5 dom6 dom7 dom8 dom9 dom10 dom11 dom12 dom13 dom14 dom15 dom16 dom17 dom18 dom19 dom20 dom21 dom22 dom23 dom24 dom25 dom26 dom27 dom28 dom29 dom30 dom31 dom32 dom33 dom34 dom35 dom36 dom37 dom38 dom39 dom40 dom41 dom42 dom43 dom44 dom45 dom46 dom47 dom48 dom49 dom50 fem1 fem2 fem3 fem4 fem5 fem6 fem7 fem8 fem9 fem10 fem11 fem12 fem13 fem14 fem15 fem16 fem17 fem18 fem19 fem20 fem21 fem22 fem23 fem24 fem25 fem26 fem27 fem28 fem29 fem30 fem31 fem32 fem33 fem34 fem35 fem36 fem37 fem38 fem39 fem40 fem41 fem42 fem43 fem44 fem45 fem46 fem47 fem48 fem49 fem50 fath1 fath2 fath3 fath4 fath5 fath6 fath7 fath8 fath9 fath10 fath11 fath12 fath13 fath14 fath15 fath16 fath17 fath18 fath19 fath20 fath21 fath22 fath23 fath24 fath25 fath26 fath27 fath28 fath29 fath30 fath31 fath32 fath33 fath34 fath35 fath36 fath37 fath38 fath39 fath40 fath41 fath42 fath43 fath44 fath45 fath46 fath47 fath48 fath49 fath50 moth1 moth2 moth3 moth4 moth5 moth6 moth7 moth8 moth9 moth10 moth11 moth12 moth13 moth14 moth15 moth16 moth17 moth18 moth19 moth20 moth21 moth22 moth23 moth24 moth25 moth26 moth27 moth28 moth29 moth30 moth31 moth32 moth33 moth34 moth35 moth36 moth37 moth38 moth39 moth40 moth41 moth42 moth43 moth44 moth45 moth46 moth47 moth48 moth49 moth50 q376 q65 q66 v455 v456 q67 q57 q58 q59 q61 q62 q92 q93 q94 q95 q96 q115 mayortype info1 info2 info3 mayor_pleased mayor_discouraged corruption_scandal corruption_type corruption_party corruption_vote corruption_feel corruption_burden    
rename (ipaddress durationinseconds finished responseid locationlatitude locationlongitude q49 q50 q51 q52 q53 q89 q90 q91 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17 a18 a19 a20 a21 a22 a23 a24 a25 a26 a27 a28 a29 a30 a31 a32 a33 a34 a35 a36 a37 a38 a39 a40 a41 a42 a43 a44 a45 a46 a47 a48 a49 a50  f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 f13 f14 f15 f16 f17 f18 f19 f20 f21 f22 f23 f24 f25 f26 f27 f28 f29 f30 f31 f32 f33 f34 f35 f36 f37 f38 f39 f40 f41 f42 f43 f44 f45 f46 f47 f48 f49 f50 m1 m2 m3 m4 m5 m6 m7 m8 m9 m10 m11 m12 m13 m14 m15 m16 m17 m18 m19 m20 m21 m22 m23 m24 m25 m26 m27 m28 m29 m30 m31 m32 m33 m34 m35 m36 m37 m38 m39 m40 m41 m42 m43 m44 m45 m46 m47 m48 m49 m50 d1 d2 d3 d4 d5 d6 d7 d8 d9 d10 d11 d12 d13 d14 d15 d16 d17 d18 d19 d20 d21 d22 d23 d24 d25 d26 d27 d28 d29 d30 d31 d32 d33 d34 d35 d36 d37 d38 d39 d40 d41 d42 d43 d44 d45 d46 d47 d48 d49 d50 g1 g2 g3 g4 g5 g6 g7 g8 g9 g10 g11 g12 g13 g14 g15 g16 g17 g18 g19 g20 g21 g22 g23 g24 g25 g26 g27 g28 g29 g30 g31 g32 g33 g34 g35 g36 g37 g38 g39 g40 g41 g42 g43 g44 g45 g46 g47 g48 g49 g50 attr1 attr2 attr3 attr4 attr5 attr6 attr7 attr8 attr9 attr10 attr11 attr12 attr13 attr14 attr15 attr16 attr17 attr18 attr19 attr20 attr21 attr22 attr23 attr24 attr25 attr26 attr27 attr28 attr29 attr30 attr31 attr32 attr33 attr34 attr35 attr36 attr37 attr38 attr39 attr40 attr41 attr42 attr43 attr44 attr45 attr46 attr47 attr48 attr49 attr50 dom1 dom2 dom3 dom4 dom5 dom6 dom7 dom8 dom9 dom10 dom11 dom12 dom13 dom14 dom15 dom16 dom17 dom18 dom19 dom20 dom21 dom22 dom23 dom24 dom25 dom26 dom27 dom28 dom29 dom30 dom31 dom32 dom33 dom34 dom35 dom36 dom37 dom38 dom39 dom40 dom41 dom42 dom43 dom44 dom45 dom46 dom47 dom48 dom49 dom50 fem1 fem2 fem3 fem4 fem5 fem6 fem7 fem8 fem9 fem10 fem11 fem12 fem13 fem14 fem15 fem16 fem17 fem18 fem19 fem20 fem21 fem22 fem23 fem24 fem25 fem26 fem27 fem28 fem29 fem30 fem31 fem32 fem33 fem34 fem35 fem36 fem37 fem38 fem39 fem40 fem41 fem42 fem43 fem44 fem45 fem46 fem47 fem48 fem49 fem50 fath1 fath2 fath3 fath4 fath5 fath6 fath7 fath8 fath9 fath10 fath11 fath12 fath13 fath14 fath15 fath16 fath17 fath18 fath19 fath20 fath21 fath22 fath23 fath24 fath25 fath26 fath27 fath28 fath29 fath30 fath31 fath32 fath33 fath34 fath35 fath36 fath37 fath38 fath39 fath40 fath41 fath42 fath43 fath44 fath45 fath46 fath47 fath48 fath49 fath50 moth1 moth2 moth3 moth4 moth5 moth6 moth7 moth8 moth9 moth10 moth11 moth12 moth13 moth14 moth15 moth16 moth17 moth18 moth19 moth20 moth21 moth22 moth23 moth24 moth25 moth26 moth27 moth28 moth29 moth30 moth31 moth32 moth33 moth34 moth35 moth36 moth37 moth38 moth39 moth40 moth41 moth42 moth43 moth44 moth45 moth46 moth47 moth48 moth49 moth50 q376 q65 q66 v455 v456 q67 q57 q58 q59 q61 q62 q92 q93 q94 q95 q96 q115 mayortype info1 info2 info3 mayor_pleased mayor_discouraged corruption_scandal corruption_type corruption_party corruption_vote corruption_feel corruption_burden) (ipaddress duration finished response_id loc_lat loc_lon pid_a pid_b pid_c pid_d ideology media_time media_type media_trust a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17 a18 a19 a20 a21 a22 a23 a24 a25 a26 a27 a28 a29 a30 a31 a32 a33 a34 a35 a36 a37 a38 a39 a40 a41 a42 a43 a44 a45 a46 a47 a48 a49 a50  f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 f13 f14 f15 f16 f17 f18 f19 f20 f21 f22 f23 f24 f25 f26 f27 f28 f29 f30 f31 f32 f33 f34 f35 f36 f37 f38 f39 f40 f41 f42 f43 f44 f45 f46 f47 f48 f49 f50 m1 m2 m3 m4 m5 m6 m7 m8 m9 m10 m11 m12 m13 m14 m15 m16 m17 m18 m19 m20 m21 m22 m23 m24 m25 m26 m27 m28 m29 m30 m31 m32 m33 m34 m35 m36 m37 m38 m39 m40 m41 m42 m43 m44 m45 m46 m47 m48 m49 m50 d1 d2 d3 d4 d5 d6 d7 d8 d9 d10 d11 d12 d13 d14 d15 d16 d17 d18 d19 d20 d21 d22 d23 d24 d25 d26 d27 d28 d29 d30 d31 d32 d33 d34 d35 d36 d37 d38 d39 d40 d41 d42 d43 d44 d45 d46 d47 d48 d49 d50 g1 g2 g3 g4 g5 g6 g7 g8 g9 g10 g11 g12 g13 g14 g15 g16 g17 g18 g19 g20 g21 g22 g23 g24 g25 g26 g27 g28 g29 g30 g31 g32 g33 g34 g35 g36 g37 g38 g39 g40 g41 g42 g43 g44 g45 g46 g47 g48 g49 g50 attr1 attr2 attr3 attr4 attr5 attr6 attr7 attr8 attr9 attr10 attr11 attr12 attr13 attr14 attr15 attr16 attr17 attr18 attr19 attr20 attr21 attr22 attr23 attr24 attr25 attr26 attr27 attr28 attr29 attr30 attr31 attr32 attr33 attr34 attr35 attr36 attr37 attr38 attr39 attr40 attr41 attr42 attr43 attr44 attr45 attr46 attr47 attr48 attr49 attr50 dom1 dom2 dom3 dom4 dom5 dom6 dom7 dom8 dom9 dom10 dom11 dom12 dom13 dom14 dom15 dom16 dom17 dom18 dom19 dom20 dom21 dom22 dom23 dom24 dom25 dom26 dom27 dom28 dom29 dom30 dom31 dom32 dom33 dom34 dom35 dom36 dom37 dom38 dom39 dom40 dom41 dom42 dom43 dom44 dom45 dom46 dom47 dom48 dom49 dom50 fem1 fem2 fem3 fem4 fem5 fem6 fem7 fem8 fem9 fem10 fem11 fem12 fem13 fem14 fem15 fem16 fem17 fem18 fem19 fem20 fem21 fem22 fem23 fem24 fem25 fem26 fem27 fem28 fem29 fem30 fem31 fem32 fem33 fem34 fem35 fem36 fem37 fem38 fem39 fem40 fem41 fem42 fem43 fem44 fem45 fem46 fem47 fem48 fem49 fem50 fath1 fath2 fath3 fath4 fath5 fath6 fath7 fath8 fath9 fath10 fath11 fath12 fath13 fath14 fath15 fath16 fath17 fath18 fath19 fath20 fath21 fath22 fath23 fath24 fath25 fath26 fath27 fath28 fath29 fath30 fath31 fath32 fath33 fath34 fath35 fath36 fath37 fath38 fath39 fath40 fath41 fath42 fath43 fath44 fath45 fath46 fath47 fath48 fath49 fath50 moth1 moth2 moth3 moth4 moth5 moth6 moth7 moth8 moth9 moth10 moth11 moth12 moth13 moth14 moth15 moth16 moth17 moth18 moth19 moth20 moth21 moth22 moth23 moth24 moth25 moth26 moth27 moth28 moth29 moth30 moth31 moth32 moth33 moth34 moth35 moth36 moth37 moth38 moth39 moth40 moth41 moth42 moth43 moth44 moth45 moth46 moth47 moth48 moth49 moth50 vote_choice vote_3p vote_novote vote_trump vote_clinton vote_open know1 know2 know3 know4 know5 age sex race education income comments mayortype info1 info2 info3 mayor_pleased mayor_discouraged corruption_scandal corruption_type corruption_party corruption_vote corruption_feel corruption_burden)                                           
order ipaddress duration finished response_id loc_lat loc_lon a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17 a18 a19 a20 a21 a22 a23 a24 a25 a26 a27 a28 a29 a30 a31 a32 a33 a34 a35 a36 a37 a38 a39 a40 a41 a42 a43 a44 a45 a46 a47 a48 a49 a50  f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 f13 f14 f15 f16 f17 f18 f19 f20 f21 f22 f23 f24 f25 f26 f27 f28 f29 f30 f31 f32 f33 f34 f35 f36 f37 f38 f39 f40 f41 f42 f43 f44 f45 f46 f47 f48 f49 f50 m1 m2 m3 m4 m5 m6 m7 m8 m9 m10 m11 m12 m13 m14 m15 m16 m17 m18 m19 m20 m21 m22 m23 m24 m25 m26 m27 m28 m29 m30 m31 m32 m33 m34 m35 m36 m37 m38 m39 m40 m41 m42 m43 m44 m45 m46 m47 m48 m49 m50 d1 d2 d3 d4 d5 d6 d7 d8 d9 d10 d11 d12 d13 d14 d15 d16 d17 d18 d19 d20 d21 d22 d23 d24 d25 d26 d27 d28 d29 d30 d31 d32 d33 d34 d35 d36 d37 d38 d39 d40 d41 d42 d43 d44 d45 d46 d47 d48 d49 d50 g1 g2 g3 g4 g5 g6 g7 g8 g9 g10 g11 g12 g13 g14 g15 g16 g17 g18 g19 g20 g21 g22 g23 g24 g25 g26 g27 g28 g29 g30 g31 g32 g33 g34 g35 g36 g37 g38 g39 g40 g41 g42 g43 g44 g45 g46 g47 g48 g49 g50 attr1 attr2 attr3 attr4 attr5 attr6 attr7 attr8 attr9 attr10 attr11 attr12 attr13 attr14 attr15 attr16 attr17 attr18 attr19 attr20 attr21 attr22 attr23 attr24 attr25 attr26 attr27 attr28 attr29 attr30 attr31 attr32 attr33 attr34 attr35 attr36 attr37 attr38 attr39 attr40 attr41 attr42 attr43 attr44 attr45 attr46 attr47 attr48 attr49 attr50 dom1 dom2 dom3 dom4 dom5 dom6 dom7 dom8 dom9 dom10 dom11 dom12 dom13 dom14 dom15 dom16 dom17 dom18 dom19 dom20 dom21 dom22 dom23 dom24 dom25 dom26 dom27 dom28 dom29 dom30 dom31 dom32 dom33 dom34 dom35 dom36 dom37 dom38 dom39 dom40 dom41 dom42 dom43 dom44 dom45 dom46 dom47 dom48 dom49 dom50 fem1 fem2 fem3 fem4 fem5 fem6 fem7 fem8 fem9 fem10 fem11 fem12 fem13 fem14 fem15 fem16 fem17 fem18 fem19 fem20 fem21 fem22 fem23 fem24 fem25 fem26 fem27 fem28 fem29 fem30 fem31 fem32 fem33 fem34 fem35 fem36 fem37 fem38 fem39 fem40 fem41 fem42 fem43 fem44 fem45 fem46 fem47 fem48 fem49 fem50 fath1 fath2 fath3 fath4 fath5 fath6 fath7 fath8 fath9 fath10 fath11 fath12 fath13 fath14 fath15 fath16 fath17 fath18 fath19 fath20 fath21 fath22 fath23 fath24 fath25 fath26 fath27 fath28 fath29 fath30 fath31 fath32 fath33 fath34 fath35 fath36 fath37 fath38 fath39 fath40 fath41 fath42 fath43 fath44 fath45 fath46 fath47 fath48 fath49 fath50 moth1 moth2 moth3 moth4 moth5 moth6 moth7 moth8 moth9 moth10 moth11 moth12 moth13 moth14 moth15 moth16 moth17 moth18 moth19 moth20 moth21 moth22 moth23 moth24 moth25 moth26 moth27 moth28 moth29 moth30 moth31 moth32 moth33 moth34 moth35 moth36 moth37 moth38 moth39 moth40 moth41 moth42 moth43 moth44 moth45 moth46 moth47 moth48 moth49 moth50 vote_choice vote_3p vote_novote vote_trump vote_clinton vote_open mayortype info1 info2 info3 mayor_pleased mayor_discouraged corruption_scandal corruption_type corruption_party corruption_vote corruption_feel corruption_burden know1 know2 know3 know4 know5 age sex race education income pid_a pid_b pid_c pid_d ideology media_time media_type media_trust comments

save tmyk3_clean, replace

*** cleaning tmyk3 pilot ***

use tmyk3pilot_raw, clear
drop if _n==1|_n==2

g mayortype=1 if q222!=""
replace mayortype=2 if q344!=""
replace mayortype=3 if q353!=""
replace mayortype=4 if q362!=""

g info1=q222 if mayortype==1
replace info1=q344 if mayortype==2
replace info1=q353 if mayortype==3
replace info1=q362 if mayortype==4
g info2=q224 if mayortype==1
replace info2=q346 if mayortype==2
replace info2=q355 if mayortype==3
replace info2=q364 if mayortype==4
g info3=q226 if mayortype==1
replace info3=q348 if mayortype==2
replace info3=q357 if mayortype==3
replace info3=q366 if mayortype==4

g mayor_pleased=q174 if mayortype==1
replace mayor_pleased=q350 if mayortype==2
replace mayor_pleased=q359 if mayortype==3
replace mayor_pleased=q368 if mayortype==4

g mayor_discouraged=q227 if mayortype==1
replace mayor_discouraged=q349 if mayortype==2
replace mayor_discouraged=q358 if mayortype==3
replace mayor_discouraged=q367 if mayortype==4

g corruption_type=1 if q204!=""|q430!=""
replace corruption_type=2 if q386!=""|q434!=""
replace corruption_type=3 if q390!=""|q438!=""
replace corruption_type=4 if q394!=""|q442!=""

g corruption_party=1 if q50!=""
replace corruption_party=2 if q51!=""

g corruption_vote=q204 if q204!=""
for any q430 q386 q434 q390 q438 q394 q442: replace corruption_vote=X if X!=""

g corruption_feel=q205 if q204!=""
for any q431 q387 q435 q391 q439 q395 q443: replace corruption_feel=X if X!=""

g corruption_burden=q206 if q204!=""
for any q432 q388 q436 q392 q440 q396 q444: replace corruption_burden=X if X!=""

keep ipaddress durationinseconds finished responseid locationlatitude locationlongitude q49 q50 q51 q52 q53 q89 q90 q91 q57 q58 q59 q61 q62 q92 q93 q94 q95 q96 q115 mayortype info1 info2 info3 mayor_pleased mayor_discouraged corruption_type corruption_party corruption_vote corruption_feel corruption_burden    
rename (ipaddress durationinseconds finished responseid locationlatitude locationlongitude q49 q50 q51 q52 q53 q89 q90 q91 q57 q58 q59 q61 q62 q92 q93 q94 q95 q96 q115 mayortype info1 info2 info3 mayor_pleased mayor_discouraged corruption_type corruption_party corruption_vote corruption_feel corruption_burden) (ipaddress duration finished response_id loc_lat loc_lon pid_a pid_b pid_c pid_d ideology media_time media_type media_trust know1 know2 know3 know4 know5 age sex race education income comments mayortype info1 info2 info3 mayor_pleased mayor_discouraged corruption_type corruption_party corruption_vote corruption_feel corruption_burden)
order ipaddress duration finished response_id loc_lat loc_lon mayortype info1 info2 info3 mayor_pleased mayor_discouraged corruption_type corruption_party corruption_vote corruption_feel corruption_burden know1 know2 know3 know4 know5 age sex race education income pid_a pid_b pid_c pid_d ideology media_time media_type media_trust comments

save tmyk3pilot_clean, replace


*** combining datasets ***

use tmyk3_clean, clear
merge 1:1 response_id using tmyk3pilot_clean
g dataset="pilot" if _merge==2
replace dataset="full" if _merge==1
drop _merge
save tmyk3_clean2, replace


*********** CLEANING THE COMBINED DATASET **************

use tmyk3_clean2, clear

*** commonly used labels and transformations ***

label variable vote_choice "1=Trump 2=Clinton 3=Stein 4=Johnson 5=Sanders 6=Other 7= No Vote"
label variable media_time "1=less than hr 2=1-3h 3=3-5h 4=5-10h 5=10h+"
label variable media_type "1=network tv 2=cable tv 3=newspapers 4=radio 5=internet news 6=internet blogs"
label variable media_trust "1=a lot 2=somewhat 3=little 4=not at all"
label variable finished "1=finished, zero otherwise"
label variable duration "time to completion in seconds"
label variable dataset "pilot = pilot data, full = study data"

g media_type_tv=1 if media_type=="1"
replace media_type_tv=1 if media_type=="1,2"
replace media_type_tv=1 if media_type=="1,2,3"
replace media_type_tv=1 if media_type=="1,2,3,4"
replace media_type_tv=1 if media_type=="1,2,3,4,5"
replace media_type_tv=1 if media_type=="1,2,3,4,5,6"
replace media_type_tv=1 if media_type=="1,2,3,5"
replace media_type_tv=1 if media_type=="1,2,3,5,6"
replace media_type_tv=1 if media_type=="1,2,4"
replace media_type_tv=1 if media_type=="1,2,4,5"
replace media_type_tv=1 if media_type=="1,2,4,5,6"
replace media_type_tv=1 if media_type=="1,2,5"
replace media_type_tv=1 if media_type=="1,2,5,6"
replace media_type_tv=1 if media_type=="1,2,6"
replace media_type_tv=1 if media_type=="1,3"
replace media_type_tv=1 if media_type=="1,3,4"
replace media_type_tv=1 if media_type=="1,3,4,5"
replace media_type_tv=1 if media_type=="1,3,4,5,6"
replace media_type_tv=1 if media_type=="1,3,5"
replace media_type_tv=1 if media_type=="1,3,5,6"
replace media_type_tv=1 if media_type=="1,4"
replace media_type_tv=1 if media_type=="1,4,5"
replace media_type_tv=1 if media_type=="1,4,5,6"
replace media_type_tv=1 if media_type=="1,5"
replace media_type_tv=1 if media_type=="1,5,6"
g media_type_cable=1 if media_type=="2"
replace media_type_cable=1 if media_type=="1,2"
replace media_type_cable=1 if media_type=="1,2,3"
replace media_type_cable=1 if media_type=="1,2,3,4,"
replace media_type_cable=1 if media_type=="1,2,3,4,5"
replace media_type_cable=1 if media_type=="1,2,3,4,5,6"
replace media_type_cable=1 if media_type=="1,2,3,5"
replace media_type_cable=1 if media_type=="1,2,3,5,6"
replace media_type_cable=1 if media_type=="1,2,4"
replace media_type_cable=1 if media_type=="1,2,4,5"
replace media_type_cable=1 if media_type=="1,2,4,5,6"
replace media_type_cable=1 if media_type=="1,2,5"
replace media_type_cable=1 if media_type=="1,2,5,6"
replace media_type_cable=1 if media_type=="1,2,6"
replace media_type_cable=1 if media_type=="2"
replace media_type_cable=1 if media_type=="2,3"
replace media_type_cable=1 if media_type=="2,3,4,5"
replace media_type_cable=1 if media_type=="2,3,5"
replace media_type_cable=1 if media_type=="2,3,5,6"
replace media_type_cable=1 if media_type=="2,3,6"
replace media_type_cable=1 if media_type=="2,4"
replace media_type_cable=1 if media_type=="2,4,5"
replace media_type_cable=1 if media_type=="2,4,5,6"
replace media_type_cable=1 if media_type=="2,5"
replace media_type_cable=1 if media_type=="2,5,6"
replace media_type_cable=1 if media_type=="2,6"
g media_type_newspaper=1 if media_type=="3"
replace media_type_newspaper=1 if media_type=="1,2,3"
replace media_type_newspaper=1 if media_type=="1,2,3,4"
replace media_type_newspaper=1 if media_type=="1,2,3,4,5"
replace media_type_newspaper=1 if media_type=="1,2,3,4,5,6"
replace media_type_newspaper=1 if media_type=="1,2,3,5"
replace media_type_newspaper=1 if media_type=="1,2,3,5,6"
replace media_type_newspaper=1 if media_type=="1,3"
replace media_type_newspaper=1 if media_type=="1,3,4"
replace media_type_newspaper=1 if media_type=="1,3,4,5"
replace media_type_newspaper=1 if media_type=="1,3,4,5,6"
replace media_type_newspaper=1 if media_type=="1,3,5"
replace media_type_newspaper=1 if media_type=="1,3,5,6"
replace media_type_newspaper=1 if media_type=="2,3"
replace media_type_newspaper=1 if media_type=="2,3,4,5"
replace media_type_newspaper=1 if media_type=="2,3,5"
replace media_type_newspaper=1 if media_type=="2,3,5,6"
replace media_type_newspaper=1 if media_type=="2,3,6"
replace media_type_newspaper=1 if media_type=="3,4"
replace media_type_newspaper=1 if media_type=="3,4,5"
replace media_type_newspaper=1 if media_type=="3,4,5,6"
replace media_type_newspaper=1 if media_type=="3,5"
g media_type_radio=1 if media_type=="4"
replace media_type_radio=1 if media_type=="1,2,3,4"
replace media_type_radio=1 if media_type=="1,2,3,4,5"
replace media_type_radio=1 if media_type=="1,2,3,4,5,6"
replace media_type_radio=1 if media_type=="1,2,4"
replace media_type_radio=1 if media_type=="1,2,4,5"
replace media_type_radio=1 if media_type=="1,2,4,5,6"
replace media_type_radio=1 if media_type=="1,3,4"
replace media_type_radio=1 if media_type=="1,3,4,5"
replace media_type_radio=1 if media_type=="1,3,4,5,6"
replace media_type_radio=1 if media_type=="1,4"
replace media_type_radio=1 if media_type=="1,4,5"
replace media_type_radio=1 if media_type=="1,4,5,6"
replace media_type_radio=1 if media_type=="2,4"
replace media_type_radio=1 if media_type=="2,4,5"
replace media_type_radio=1 if media_type=="2,4,5,6"
replace media_type_radio=1 if media_type=="3,4"
replace media_type_radio=1 if media_type=="3,4,5"
replace media_type_radio=1 if media_type=="3,4,5,6"
replace media_type_radio=1 if media_type=="4,5"
replace media_type_radio=1 if media_type=="4,5,6"
replace media_type_radio=1 if media_type=="4,6"
g media_type_internet=1 if media_type=="5"
replace media_type_internet=1 if media_type=="1,2,3,4,5"
replace media_type_internet=1 if media_type=="1,2,3,4,5,6"
replace media_type_internet=1 if media_type=="1,2,3,5"
replace media_type_internet=1 if media_type=="1,2,3,5,6"
replace media_type_internet=1 if media_type=="1,2,4,5"
replace media_type_internet=1 if media_type=="1,2,4,5,6"
replace media_type_internet=1 if media_type=="1,2,5"
replace media_type_internet=1 if media_type=="1,2,5,6"
replace media_type_internet=1 if media_type=="1,3,4,5"
replace media_type_internet=1 if media_type=="1,3,4,5,6"
replace media_type_internet=1 if media_type=="1,3,5"
replace media_type_internet=1 if media_type=="1,3,5,6"
replace media_type_internet=1 if media_type=="1,4,5"
replace media_type_internet=1 if media_type=="1,4,5,6"
replace media_type_internet=1 if media_type=="1,5"
replace media_type_internet=1 if media_type=="1,5,6"
replace media_type_internet=1 if media_type=="2,3,4,5"
replace media_type_internet=1 if media_type=="2,3,5"
replace media_type_internet=1 if media_type=="2,3,5,6"
replace media_type_internet=1 if media_type=="2,4,5"
replace media_type_internet=1 if media_type=="2,4,5,6"
replace media_type_internet=1 if media_type=="2,5"
replace media_type_internet=1 if media_type=="2,5,6"
replace media_type_internet=1 if media_type=="3,4,5"
replace media_type_internet=1 if media_type=="3,4,5,6"
replace media_type_internet=1 if media_type=="3,5"
replace media_type_internet=1 if media_type=="4,5"
replace media_type_internet=1 if media_type=="4,5,6"
replace media_type_internet=1 if media_type=="5,6"
g media_type_blogs=1 if media_type=="6"
replace media_type_blogs=1 if media_type=="1,2,3,4,5,6"
replace media_type_blogs=1 if media_type=="1,2,3,5,6"
replace media_type_blogs=1 if media_type=="1,2,4,5,6"
replace media_type_blogs=1 if media_type=="1,2,5,6"
replace media_type_blogs=1 if media_type=="1,2,6"
replace media_type_blogs=1 if media_type=="1,3,4,5,6"
replace media_type_blogs=1 if media_type=="1,3,5,6"
replace media_type_blogs=1 if media_type=="1,4,5,6"
replace media_type_blogs=1 if media_type=="1,5,6"
replace media_type_blogs=1 if media_type=="2,3,5,6"
replace media_type_blogs=1 if media_type=="2,3,6"
replace media_type_blogs=1 if media_type=="2,4,5,6"
replace media_type_blogs=1 if media_type=="2,5,6"
replace media_type_blogs=1 if media_type=="2,6"
replace media_type_blogs=1 if media_type=="3,4,5,6"
replace media_type_blogs=1 if media_type=="4,5,6"
replace media_type_blogs=1 if media_type=="4,6"
replace media_type_blogs=1 if media_type=="5,6"
replace media_type_tv=0 if media_type_tv==. & dataset=="thirdparties"
replace media_type_cable=0 if media_type_cable==. & dataset=="thirdparties"
replace media_type_newspaper=0 if media_type_newspaper==. & dataset=="thirdparties"
replace media_type_radio=0 if media_type_radio==. & dataset=="thirdparties"
replace media_type_internet=0 if media_type_internet==. & dataset=="thirdparties"
replace media_type_blogs=0 if media_type_blogs==. & dataset=="thirdparties"

*** commonly used labels and transformations ***
destring know1-know5 age race education pid_a pid_b pid_c pid_d, replace
g gk1=know1==1
g gk2=know2==1
g gk3=know3==3
g gk4=know4==1
g gk5=know5==1
g soph=gk1+gk2+gk3+gk4+gk5
label variable soph "general political knowledge, 0-5"
g sophsimple=soph>2
label variable sophsimple "0=low tier, 1=high tier"
replace age=4 if age==5
label variable age "1=18-25 2=26-34 3=35-54 4=55+"
label variable sex "1=m 2=f"
g race_minority = race!=1
label variable race "1=white 2=black 3=latino 4=asian 5=native 6=islander 7=other"
label variable race_minority "1=minority, zero otherwise"
label variable education "1=less HS 2=HS 3=some coll 4=AA 5=BA 6=MA 7=PhD 8=Prof"
g edsimple = 1 if education==1|education==2
replace edsimple = 2 if education==3
replace edsimple = 3 if education==4|education==5
replace edsimple = 4 if education>5
label variable edsimple "1=HS or less, 2=some college, 3=bachelors or AA, 4=MA, PhD, Professional"
label variable income "1=less than 30k, 2-8=10k increments up 9=100k or more"
g incomesimple =1 if income=="1"
replace incomesimple =2 if income=="2"|income=="3"|income=="4"
replace incomesimple =3 if income=="5"|income=="6"|income=="7"|income=="8"
replace incomesimple =4 if income=="9"
label variable incomesimple "1=less than 30k, 2=30k-60k 3=60k-100k 4=100k+"
g party=1 if pid_a==1 & pid_b==1
replace party=2 if pid_a==1 & pid_b==2
replace party=3 if (pid_a==3|pid_a==4) & pid_d==2
replace party=4 if pid_d==4
replace party=5 if (pid_a==3|pid_a==4) & pid_d==1
replace party=6 if pid_a==2 & pid_c==2
replace party=7 if pid_a==2 & pid_c==1
g partydum=1 if party<4
replace partydum=2 if party>4
replace partydum=3 if party==4

destring duration finished loc_lat loc_lon a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17 a18 a19 a20 a21 a22 a23 a24 a25 a26 a27 a28 a29 a30 a31 a32 a33 a34 a35 a36 a37 a38 a39 a40 a41 a42 a43 a44 a45 a46 a47 a48 a49 a50 f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 f13 f14 f15 f16 f17 f18 f19 f20 f21 f22 f23 f24 f25 f26 f27 f28 f29 f30 f31 f32 f33 f34 f35 f36 f37 f38 f39 f40 f41 f42 f43 f44 f45 f46 f47 f48 f49 f50 m1 m2 m3 m4 m5 m6 m7 m8 m9 m10 m11 m12 m13 m14 m15 m16 m17 m18 m19 m20 m21 m22 m23 m24 m25 m26 m27 m28 m29 m30 m31 m32 m33 m34 m35 m36 m37 m38 m39 m40 m41 m42 m43 m44 m45 m46 m47 m48 m49 m50 d1 d2 d3 d4 d5 d6 d7 d8 d9 d10 d11 d12 d13 d14 d15 d16 d17 d18 d19 d20 d21 d22 d23 d24 d25 d26 d27 d28 d29 d30 d31 d32 d33 d34 d35 d36 d37 d38 d39 d40 d41 d42 d43 d44 d45 d46 d47 d48 d49 d50 g1 g2 g3 g4 g5 g6 g7 g8 g9 g10 g11 g12 g13 g14 g15 g16 g17 g18 g19 g20 g21 g22 g23 g24 g25 g26 g27 g28 g29 g30 g31 g32 g33 g34 g35 g36 g37 g38 g39 g40 g41 g42 g43 g44 g45 g46 g47 g48 g49 g50 attr1 attr2 attr3 attr4 attr5 attr6 attr7 attr8 attr9 attr10 attr11 attr12 attr13 attr14 attr15 attr16 attr17 attr18 attr19 attr20 attr21 attr22 attr23 attr24 attr25 attr26 attr27 attr28 attr29 attr30 attr31 attr32 attr33 attr34 attr35 attr36 attr37 attr38 attr39 attr40 attr41 attr42 attr43 attr44 attr45 attr46 attr47 attr48 attr49 attr50 dom1 dom2 dom3 dom4 dom5 dom6 dom7 dom8 dom9 dom10 dom11 dom12 dom13 dom14 dom15 dom16 dom17 dom18 dom19 dom20 dom21 dom22 dom23 dom24 dom25 dom26 dom27 dom28 dom29 dom30 dom31 dom32 dom33 dom34 dom35 dom36 dom37 dom38 dom39 dom40 dom41 dom42 dom43 dom44 dom45 dom46 dom47 dom48 dom49 dom50 fem1 fem2 fem3 fem4 fem5 fem6 fem7 fem8 fem9 fem10 fem11 fem12 fem13 fem14 fem15 fem16 fem17 fem18 fem19 fem20 fem21 fem22 fem23 fem24 fem25 fem26 fem27 fem28 fem29 fem30 fem31 fem32 fem33 fem34 fem35 fem36 fem37 fem38 fem39 fem40 fem41 fem42 fem43 fem44 fem45 fem46 fem47 fem48 fem49 fem50 fath1 fath2 fath3 fath4 fath5 fath6 fath7 fath8 fath9 fath10 fath11 fath12 fath13 fath14 fath15 fath16 fath17 fath18 fath19 fath20 fath21 fath22 fath23 fath24 fath25 fath26 fath27 fath28 fath29 fath30 fath31 fath32 fath33 fath34 fath35 fath36 fath37 fath38 fath39 fath40 fath41 fath42 fath43 fath44 fath45 fath46 fath47 fath48 fath49 fath50 moth1 moth2 moth3 moth4 moth5 moth6 moth7 moth8 moth9 moth10 moth11 moth12 moth13 moth14 moth15 moth16 moth17 moth18 moth19 moth20 moth21 moth22 moth23 moth24 moth25 moth26 moth27 moth28 moth29 moth30 moth31 moth32 moth33 moth34 moth35 moth36 moth37 moth38 moth39 moth40 moth41 moth42 moth43 moth44 moth45 moth46 moth47 moth48 moth49 moth50 vote_choice vote_3p vote_novote vote_trump vote_clinton mayortype mayor_pleased mayor_discouraged corruption_scandal corruption_type corruption_party corruption_vote corruption_feel corruption_burden know1 know2 know3 know4 know5 age sex race education income pid_a pid_b pid_c pid_d ideology media_time media_type media_trust gk1 gk2 gk3 gk4 gk5 soph, replace

g ideodum=1 if ideology<4
replace ideodum=3 if party>4
replace ideodum=2 if party==4
g extreme = 0 if ideology==4
replace extreme = 1 if ideology==3|ideology==5
replace extreme = 2 if ideology==2|ideology==6
replace extreme = 3 if ideology==1|ideology==7
g party_extreme=0 if party==4
replace party_extreme=1 if (party==3|party==5)
replace party_extreme=2 if (party==2|party==6)
replace party_extreme=3 if (party==1|party==7)
label variable party "1-7, strong.democrat-strong.republican"
label variable partydum "1=d 2=r 3=i"
label variable ideology "1-7, very.liberal-very.conservative, 8=dk"
label variable ideodum "1=lib, 2=mod 3=con"
label variable extreme "0-3, low to high ideological extremity"
label variable party_extreme "0-3, low to high partisan extremity"

recode vote_3p (5 = 1) (1 = 4)
g vote_change=vote_3p if vote_3p!=.
for any clinton trump novote: replace vote_change=vote_X if vote_X!=.
label variable vote_change "1=novote, 2=Clinton, 3=Trump, 4=3p"

g vote_flip=1 if (vote_choice==1&vote_change!=3)|(vote_choice==2&vote_change!=2)|(vote_choice==3&vote_change!=4)|(vote_choice==4&vote_change!=4)|(vote_choice==5&vote_change!=4)|(vote_choice==6&vote_change!=4)|(vote_choice==7&vote_change!=1)
replace vote_flip=0 if vote_flip==.
label variable vote_flip "1=changed, 0 otherwise"

tab vote_choice vote_change, row

tab comments
drop if comments=="delete its sean"|comments=="delete this it's sean"

drop gk1-gk5 media_type comments pid_b-pid_d know1-know5
label variable mayor_pleased "1-7, 1=not vote, 7=definitely vote"
label variable mayor_discouraged "1-7, 1=not vote, 7=definitely vote"
label variable mayortype "1=bf 2=bm 3=wf 4=wm"
label variable corruption_scandal "1=sex 2=legal 3=financial"
label variable corruption_type "1=bf 2=bm 3=wf 4=wm"
label variable corruption_party "1=d 2=r 3=i"
label variable corruption_vote "1=candidate, 2=opponent, 3=not vote, 4=3p"
label variable corruption_feel "1-4, 1=no change, 4=much more negative"
label variable corruption_burden "1=innocent til proven, 2=maybe guilty, 3=likely guilty"

g choice=1 if vote_choice==1
replace choice=2 if vote_choice==2
replace choice=3 if vote_choice==3|vote_choice==4|vote_choice==5|vote_choice==6
replace choice=4 if vote_choice==7
label variable choice "1=trump 2=clinton 3=3p 4=no vote"

g choice_clinton=1 if vote_flip==1 & vote_change==2
replace choice_clinton=0 if vote_flip==0|(vote_flip==1&vote_change!=2)

g remorse=1 if (choice==3|choice==4)&choice_clinton==1
replace remorse=0 if (choice==3|choice==4)&choice_clinton==0

g remorse2=1 if (choice==3|choice==4)&vote_flip==1
replace remorse2=0 if (choice==3|choice==4)&vote_flip==0

g novote_remorse=1 if (choice==4)&choice_clinton==1
replace novote_remorse=0 if (choice==4)&choice_clinton==0

g novote_remorse2=1 if (choice==4)&vote_flip==1
replace novote_remorse2=0 if (choice==4)&vote_flip==0

g p3_remorse=1 if (choice==3)&choice_clinton==1
replace p3_remorse=0 if (choice==3)&choice_clinton==0

g p3_remorse2=1 if (choice==3)&vote_flip==1
replace p3_remorse2=0 if (choice==3)&vote_flip==0

g changetype=0 if vote_flip==0
replace changetype=1 if vote_flip==1 & vote_change==2
replace changetype=2 if vote_flip==1 & vote_change==3
replace changetype=3 if vote_flip==1 & vote_change==4
replace changetype=4 if vote_flip==1 & vote_change==1
label variable changetype "0=no change, 1=clinton, 2=trump, 3=3p, 4=novote"

g vote_choice2 = 1 if vote_choice==1
replace vote_choice2 = 2 if vote_choice==2
replace vote_choice2 = 3 if (vote_choice==3|vote_choice==4|vote_choice==5|vote_choice==6)
replace vote_choice2 = 4 if vote_choice==7

recode vote_change (1=4) (3=1) (4=3)
label variable vote_change "1=trump 2=clinton 3=3p 4=no vote"
drop a1-moth50


save tmyk3data, replace


************** MERGING FROM PART 1 AND PART 2 ************

use tmyk3_recoded, clear
merge m:1 response_id using tmyk3data

drop ipaddress-loc_lon vote_open info1-info3 _merge

saveold tmyk3_recoded_forsean, replace



************************************************
******* GENERATING DATASET FOR 4TH STUDY *******
************************************************

*** converting to dta ***

insheet using "dealbreaker.csv", names clear
drop if _n<3
save dealbreaker, replace












************************************************
************************************************
******* CREATING THE POOLED ANALYSIS SET *******
************************************************
************************************************


*** WE CREATE TWO MAIN DATASETS: ONE AT THE IND
*** LEVEL, AND ONE AT THE REQUEST LEVEL. THESE
*** ARE EACH CREATED SEPARATELY BELOW.


******************************
***** REQUEST LEVEL DATA *****
******************************


*************** TMYK, 1ST STUDY ****************

use "CJCodes_full.dta", clear

g rank=1 if _n<1207
replace rank=2 if _n<2413 & rank!=1
replace rank=3 if rank!=1&rank!=2

keep o_allinfo rank o_type o_att o_atttype mayorcondition party partydum ideology extreme soph age sex race edu income qualtrics_id
rename o_allinfo info
rename party pid_7
rename partydum pid_3
rename o_att att
recode age (4=3) (5=4)
g att_badgood = 1 if (o_atttype==3|o_atttype==4)
replace att_badgood = 0 if (o_atttype==1|o_atttype==2)
g att_earlylater = 1 if (o_atttype==1|o_atttype==3)
replace att_earlylater = 0 if (o_atttype==2|o_atttype==4)
tostring info, replace

g type="jada" if (mayorcondition==4)
replace type="jenna" if (mayorcondition==6)
replace type="jamal" if (mayorcondition==5)
replace type="jake" if (mayorcondition==7)

g mayor_gender=1 if (mayorcondition==4|mayorcondition==6)
replace mayor_gender=2 if (mayorcondition==5|mayorcondition==7)
label var mayor_gender "1=female 2=male"

g mayor_race=1 if (mayorcondition==4|mayorcondition==5)
replace mayor_race=2 if (mayorcondition==7|mayorcondition==6)
label var mayor_race "1=black 2=white"

g dataset=1
label var dataset "1=TMYK1, 2=TMYK2, 3=TMYK3"

save master1, replace


*************** TMYK, 2ND STUDY ****************

use tmyk2_full_forsean, clear

replace edu=8 if edu==9999987
g o_type=1 if office=="Mayor"
replace o_type=4 if office=="Clerk"
replace o_type=5 if office=="Comptroller"
replace o_type=6 if office=="Judge"

keep info rank o_type pid_7 pid_3 ideology extremity officeknowl age_st sex race edu income
recode age_st (4=3) (5=4)
rename age_st age
replace pid_3="1" if pid_3=="D"
replace pid_3="2" if pid_3=="R"
replace pid_3="3" if pid_3=="I"
destring pid_3, replace
rename extremity extreme

g dataset=2
label var dataset "1=TMYK1, 2=TMYK2, 3=TMYK3"

save master2, replace


*************** TMYK, 3RD STUDY ****************

use tmyk3_recoded_forsean, clear

g type="jada" if (mayortype==1)
replace type="jenna" if (mayortype==3)
replace type="jamal" if (mayortype==2)
replace type="jake" if (mayortype==4)

g info = recode
replace info = mstring if info==""
replace info="492" if id==671 & _j==2
replace info="492" if id==981 & _j==2
replace info="492" if id==498 & _j==3
replace info="492" if id==765 & _j==3
replace info="492" if id==841 & _j==3

rename _j rank

g mayor_gender=1 if (mayortype==1|mayortype==3)
replace mayor_gender=2 if (mayortype==2|mayortype==4)
label var mayor_gender "1=female 2=male"

g mayor_race=1 if (mayortype==1|mayortype==2)
replace mayor_race=2 if (mayortype==3|mayortype==4)
label var mayor_race "1=black 2=white"

rename party pid_7
rename partydum pid_3
rename party_extreme extremity

recode age (4=3)

g o_atttype=1 if (mayor_discouraged!=.)
replace o_atttype=3 if (mayor_pleased!=.)

g mayor_pleased2=mayor_pleased
replace mayor_pleased2=. if (mayor_pleased2==1|mayor_pleased2==2|mayor_pleased2==3)
recode mayor_pleased2 (4=4) (5=3) (6=2) (7=1)

g mayor_discouraged2=mayor_discouraged
replace mayor_discouraged2=. if (mayor_discouraged2==5|mayor_discouraged2==6|mayor_discouraged2==7)

g o_att=mayor_pleased2 if mayor_pleased2!=.
replace o_att=mayor_discouraged2 if mayor_discouraged2!=.

keep info rank type mayor_gender mayor_race o_att o_atttype pid_7 pid_3 ideology extremity soph age sex race edu income

g o_type=1

g dataset=3
label var dataset "1=TMYK1, 2=TMYK2, 3=TMYK3"

save master3, replace


*************** TMYK, 4TH STUDY ****************

use dealbreaker, clear

destring jada_diss, replace
destring jada_enc, replace
destring jenn_enc, replace
destring jenna_diss, replace
destring jamal_diss, replace
destring jamal_enc, replace
destring jake_diss, replace
destring jake_enc, replace

g att=jada_diss if jada_diss!=.
replace att=jada_enc if jada_enc!=.
replace att=jamal_enc if jamal_enc!=.
replace att=jamal_diss if jamal_diss!=.
replace att=jenn_enc if jenn_enc!=.
replace att=jenna_diss if jenna_diss!=.
replace att=jake_enc if jake_enc!=.
replace att=jake_diss if jake_diss!=.

g att_badgood=1 if (jada_enc!=.|jenn_enc!=.|jamal_enc!=.|jake_enc!=.)
replace att_badgood=0 if (jada_diss!=.|jenna_diss!=.|jamal_diss!=.|jake_diss!=.)

keep att att_badgood

g dataset=4

save master4, replace



*********** COMBINING ALL TMYK3 DATASETS *************

use master1, clear
append using master2
append using master3
append using master4

rename type m_type
rename mayor_gender m_gender
rename mayor_race m_race

label var rank "1=first info, 2=second info, 3=third info"
label var m_type "name of candidate"
replace mayorcondition=4 if m_type=="jada"
replace mayorcondition=5 if m_type=="jamal"
replace mayorcondition=6 if m_type=="jenna"
replace mayorcondition=7 if m_type=="jake"
label var pid_7 "1-7 strong democrat-strong republican"
label var pid_3 "1=D, 2=R, 3=I"
label var ideology "1-7 strong liberal-strong conservative"
label var soph "0-5, low-high"
replace edu=education if dataset==3
drop education

order info rank o_type m_type m_gender m_race mayorcondition dataset soph edu pid_3 pid_7 extremity ideology age sex race

g subcat = substr(info,1,1)
g subsub = substr(info,1,2)

destring subcat, replace
destring subsub, replace
destring info, replace

g goodinfo1=1 if (subcat<4)
replace goodinfo1=0 if subcat==4|subcat==5
label var goodinfo1 "1 only if asking for political or policy information"

g goodinfo2=1 if (subcat<4 & subsub!=24 & subsub!=34)
replace goodinfo2=0 if subcat==4|subcat==5|subsub==24|subsub==34
label var goodinfo2 "1 only if asking for political info or SPECIFIC policy information"

g goodinfo3=1 if (subcat<4)|(subsub==41|subsub==43|subsub==48)
replace goodinfo3=0 if (subcat==4 & subsub!=41 & subsub!=43 & subsub!=48)|subcat==5
label var goodinfo3 "1 if in 100/200/300 categories OR is 410/430/480"

g goodinfo4=1 if (subcat<4 & subsub!=24 & subsub!=34)|(subsub==41|subsub==43|subsub==48)
replace goodinfo4=0 if (subcat==4 & subsub!=41 & subsub!=43 & subsub!=48)|subcat==5|subsub==24|subsub==34
label var goodinfo4 "1 if in 100s, 200s/300s (without general categories), OR is 410/430/480"

g ginfo1=1 if subcat<4
replace ginfo1=0 if ginfo1!=1 & subcat!=. & subcat!=7
g binfo1=1 if (subcat>3) & subcat!=7 & subcat!=.
replace binfo1=0 if binfo1!=1 & subcat!=. & subcat!=7

g ginfo2=(subcat<4 & subsub!=24 & subsub!=34)
replace ginfo2=0 if ginfo2!=1 & subcat!=. & subcat!=7
g binfo2=((subcat>3|subsub==24|subsub==34) & subcat!=7)& subcat!=.
replace binfo2=0 if binfo2!=1 & subcat!=. & subcat!=7

g ginfo3=(subcat<4)|(subsub==41|subsub==43|subsub==48)
replace ginfo3=0 if ginfo3!=1 & subcat!=. & subcat!=7
g binfo3=(subcat>3)&subsub!=41&subsub!=43&subsub!=48&subcat!=7& subcat!=.
replace binfo3=0 if binfo3!=1 & subcat!=. & subcat!=7

g ginfo4=(subcat<4 & subsub!=24 & subsub!=34)|subsub==41|subsub==43|subsub==48
replace ginfo4=0 if ginfo4!=1 & subcat!=. & subcat!=7
g binfo4=(subcat>3|subsub==24|subsub==34)&subsub!=41&subsub!=43&subsub!=48&subcat!=7& subcat!=.
replace binfo4=0 if binfo4!=1 & subcat!=. & subcat!=7

save TMYK3_pooled, replace
outsheet using "TMYK3_pooled.csv", comma replace 



*********************************
***** INDIVIDUAL LEVEL DATA *****
*********************************

*************** TMYK, 1ST STUDY ****************

use "CJCodes_full.dta", clear

g rank=1 if _n<1207
replace rank=2 if _n<2413 & rank!=1
replace rank=3 if rank!=1&rank!=2

keep id o_allinfo rank o_type o_att o_atttype mayorcondition party partydum ideology extreme soph age sex race edu income
rename o_allinfo info
rename party pid_7
rename partydum pid_3
rename o_att att
recode age (4=3) (5=4)
g att_badgood = 1 if (o_atttype==3|o_atttype==4)
replace att_badgood = 0 if (o_atttype==1|o_atttype==2)
g att_earlylater = 1 if (o_atttype==1|o_atttype==3)
replace att_earlylater = 0 if (o_atttype==2|o_atttype==4)
tostring info, replace

g type="jada" if (mayorcondition==4)
replace type="jenna" if (mayorcondition==6)
replace type="jamal" if (mayorcondition==5)
replace type="jake" if (mayorcondition==7)

g mayor_gender=1 if (mayorcondition==4|mayorcondition==6)
replace mayor_gender=2 if (mayorcondition==5|mayorcondition==7)
label var mayor_gender "1=female 2=male"

g mayor_race=1 if (mayorcondition==4|mayorcondition==5)
replace mayor_race=2 if (mayorcondition==7|mayorcondition==6)
label var mayor_race "1=black 2=white"

g dataset=1
label var dataset "1=TMYK1, 2=TMYK2, 3=TMYK3"

drop if id==.
reshape wide info, i(id o_type) j(rank)

save master1ind, replace


*************** TMYK, 2ND STUDY ****************

use tmyk2_full_forsean, clear

replace edu=8 if edu==9999987
g o_type=1 if office=="Mayor"
replace o_type=4 if office=="Clerk"
replace o_type=5 if office=="Comptroller"
replace o_type=6 if office=="Judge"

keep id info rank o_type pid_7 pid_3 ideology extremity officeknowl age_st sex race edu income
recode age_st (4=3) (5=4)
rename age_st age
replace pid_3="1" if pid_3=="D"
replace pid_3="2" if pid_3=="R"
replace pid_3="3" if pid_3=="I"
destring pid_3, replace
rename extremity extreme

g dataset=2
label var dataset "1=TMYK1, 2=TMYK2, 3=TMYK3"

reshape wide info, i(id) j(rank)

save master2ind, replace


*************** TMYK, 3RD STUDY ****************

use tmyk3_recoded_forsean, clear

g type="jada" if (mayortype==1)
replace type="jenna" if (mayortype==3)
replace type="jamal" if (mayortype==2)
replace type="jake" if (mayortype==4)

g info = recode
replace info = mstring if info==""
replace info="492" if id==671 & _j==2
replace info="492" if id==981 & _j==2
replace info="492" if id==498 & _j==3
replace info="492" if id==765 & _j==3
replace info="492" if id==841 & _j==3

rename _j rank

g mayor_gender=1 if (mayortype==1|mayortype==3)
replace mayor_gender=2 if (mayortype==2|mayortype==4)
label var mayor_gender "1=female 2=male"

g mayor_race=1 if (mayortype==1|mayortype==2)
replace mayor_race=2 if (mayortype==3|mayortype==4)
label var mayor_race "1=black 2=white"

rename party pid_7
rename partydum pid_3
rename party_extreme extremity

recode age (4=3)


g o_atttype=1 if (mayor_discouraged!=.)
replace o_atttype=3 if (mayor_pleased!=.)

g o_att=mayor_pleased if mayor_pleased!=.
replace o_att=mayor_discouraged if mayor_discouraged!=.


keep id info rank type mayor_gender mayor_race pid_7 pid_3 ideology extremity soph age sex race edu income

g o_type=1

g dataset=3
label var dataset "1=TMYK1, 2=TMYK2, 3=TMYK3"

reshape wide info, i(id) j(rank)

save master3ind, replace


*********** COMBINING ALL TMYK3 DATASETS *************

use master1ind, clear
append using master2ind
append using master3ind

rename type m_type
rename mayor_gender m_gender
rename mayor_race m_race

label var m_type "name of candidate"
replace mayorcondition=4 if m_type=="jada"
replace mayorcondition=5 if m_type=="jamal"
replace mayorcondition=6 if m_type=="jenna"
replace mayorcondition=7 if m_type=="jake"
label var pid_7 "1-7 strong democrat-strong republican"
label var pid_3 "1=D, 2=R, 3=I"
label var ideology "1-7 strong liberal-strong conservative"
label var soph "0-5, low-high"
label var officeknowl "0-1, low-high"
replace edu=education if dataset==3
drop education

order id info1 info2 info3 o_type m_type m_gender m_race mayorcondition dataset soph officeknowl edu pid_3 pid_7 extremity ideology age sex race

g subcat1 = substr(info1,1,1)
g subsub1 = substr(info1,1,2)
g subcat2 = substr(info2,1,1)
g subsub2 = substr(info2,1,2)
g subcat3 = substr(info3,1,1)
g subsub3 = substr(info3,1,2)

destring subcat1, replace
destring subsub1, replace
destring info1, replace
destring subcat2, replace
destring subsub2, replace
destring info2, replace
destring subcat3, replace
destring subsub3, replace
destring info3, replace

save TMYK3_pooled_ind, replace
outsheet using "TMYK3_pooled_ind.csv", comma replace 







